home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: InfoMgt / InfoMgt.zip / VIDCAT_C.ZIP / VIDEOCAT.C
C/C++ Source or Header  |  1988-10-22  |  435KB  |  8,186 lines

  1. #pragma comment(exestr, "Copyright 1986, 1987, 1988 W. A. Jackson")
  2. #pragma comment(compiler)
  3. #pragma comment(exestr, "Compiled on "__DATE__ "at " __TIME__)
  4. #pragma skip(10)
  5. /*
  6.  
  7.              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8.                             VIDEOCAT 
  9.  
  10.                            Version 6.0
  11.  
  12.                            Source Code
  13.  
  14.              Copyright 1986, 1987, 1988 W. A. Jackson
  15.  
  16.              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  17. */
  18. #pragma skip(20)
  19. /*
  20.      Requires Microsoft C Version 5.10 or later running under OS/2
  21.      Recommended command line options:
  22.  
  23.           cl /Lp /AL /Fb /F F00 videocat.c
  24. */
  25. #pragma title(__FILE__)
  26. #pragma subtitle("Compiled on " __DATE__ " at " __TIME__)
  27. #pragma page()
  28.  
  29. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv header vvvv*/
  30. /*-----------------------------------------------------------------------------
  31.                     Header for source file begins here.
  32.  
  33. (If the program is divided into smaller files for more convenient editing or
  34. more efficient compiler optimizaton, each source file should include the
  35. same header code.) 
  36.  
  37. -----------------------------------------------------------------------------*/
  38.  
  39. /*------------------------------------------ Compiler-Related Directives ----*/
  40.  
  41.  
  42. #define INCL_BASE  1  /* causes all OS/2 base definitions to be included */
  43. #define LINT_ARGS  1  /* causes argument checking for library functions
  44.                          in Microsoft C; has no effect under other
  45.                          compilers */
  46.  
  47. /*---------------------------------------------------------------------------*/
  48.  
  49. /*-------------------------------------------------------- Include Files ----*/
  50. /*
  51.      Include files contain macro and constant definitions, type
  52.      definitions, and function declarations:
  53.      
  54.      stdio.h        for stream I/O
  55.      ctype.h        for character classification
  56.      dos.h          for MS-DOS interface functions
  57.      fcntl.h        for low-level flag definitions
  58.      io.h           for low-level I/O
  59.      string.h       for string manipulation functions
  60.      direct.h       for directory control functions
  61.      malloc.h       for memory allocation functions
  62.      memory.h       for buffer manipulation routines
  63.      os2.h          top level include file for OS/2 applications
  64.      stdlib.h       for miscellaneous utilities
  65.      sys\stat.h     for status information functions
  66.      sys\types.h    for system-level calls
  67.      time.h         for time routines
  68.      
  69. The #include directive causes the contents of an "include" file to be added
  70. to the source file during preprocessing.
  71.      
  72. */
  73.  
  74. #include <stdio.h>
  75. #include <ctype.h>
  76. #include <dos.h>
  77. #include <string.h>
  78. #include <direct.h>
  79. #include <fcntl.h>
  80. #include <io.h>
  81. #include <malloc.h>
  82. #include <memory.h>
  83. #include <time.h>
  84. #include <sys\types.h>
  85. #include <sys\stat.h>
  86. #include <stdlib.h>
  87. #include <os2.h>
  88.  
  89.  
  90.  
  91. /*---------------------------------------------------------------------------*/
  92. #pragma subtitle("Manifest Constants")
  93. #pragma page()
  94.  
  95. /*--------------------------------------------------- Manifest Constants ----*/
  96.  
  97. /*
  98.     The #define directive is used here to associate meaningful identifiers
  99.     to constants frequently used in statements or expressions.
  100. */  
  101.  
  102.                           /* Constants */
  103.                           
  104.  
  105. #define BIGBUFF         0x1000
  106. #define BLANK_LINE      "                                        \
  107.                                        "
  108. #define BLACK           0x0
  109. #define BLUE            0x1
  110. #define BROWN           0x6 
  111. #define CGACURSNORM     0x0607
  112. #define CODENUMBER      42
  113. #define CURSOFF         0x2000
  114. #define CYAN            0x3
  115. #ifndef FALSE
  116. #define FALSE           00
  117. #endif
  118. #define FIDLENGTH       14
  119. #define FORMLENGTH      16 
  120. #define FORMNUMBER      24
  121. #define GREEN           0x2
  122. #define INPUTLENGTH     80
  123. #define LBLACK          0x8
  124. #define LBLUE           0x9
  125. #define LCYAN           0xB
  126. #define LGREEN          0xA
  127. #define LMAGENTA        0xD 
  128. #define LOCLENGTH       05
  129. #define LRED            0xC
  130. #define LWHITE          0xF
  131. #define MAGENTA         0x5
  132. #define MAXRECORDS      9999
  133. #define MONOCURSNORM    0x0C0D
  134. #define MPAANUMBER      6
  135. #define NAMELENGTH      31
  136. #define PHRASELENGTH    16
  137. #define RATINGNUMBER    8
  138. #define RED             0x4
  139. #define SUBJLENGTH      16
  140. #define SUBJNUMBER      42
  141. #define TITLELENGTH     41
  142. #ifndef TRUE
  143. #define TRUE            01
  144. #endif
  145. #define WHITE           0x7
  146. #define YEARLENGTH      05
  147. #define YELLOW          0xE
  148.  
  149. /*---------------------------------------------------------------------------*/
  150.  
  151. #pragma subtitle("Type Declarations")
  152. #pragma page()
  153.  
  154. /*---------------------------------------------------- Type Declarations ----*/
  155.  
  156. /*
  157.     The typedef declarations used here establish names for complex
  158.     user-defined structure data types used throughout the program.
  159. */
  160.  
  161.                             /*  Types  */
  162.  
  163.  
  164. typedef struct      LABELNODE  {
  165.                         char title [TITLELENGTH];    
  166.                         char loc1 [LOCLENGTH];
  167.                         char loc2 [LOCLENGTH];
  168.                         SEL  sel;
  169.                         struct LABELNODE  *lnode;     
  170.                         struct LABELNODE  *rnode;     
  171.                         };
  172.  
  173. typedef struct          LABELDATA  {
  174.                         char *loc1 [LOCLENGTH];
  175.                         int  *line_count;
  176.                         int  *label_count;
  177.                         };
  178.                         
  179. typedef struct      MOVIERECORD {
  180.                         char title [TITLELENGTH];
  181.                         char year [YEARLENGTH];
  182.                         char star1 [NAMELENGTH];
  183.                         char star2 [NAMELENGTH];
  184.                         char star3 [NAMELENGTH];
  185.                         char director [NAMELENGTH];
  186.                         char subject;
  187.                         char form;
  188.                         char rating;
  189.                         char loc1 [LOCLENGTH];
  190.                         char loc2 [LOCLENGTH];
  191.                         char mpaa_code;
  192.                         };
  193.  
  194. typedef struct      MOVIETRANS {
  195.                         char transaction;
  196.                         struct MOVIERECORD moviedata;
  197.                         SEL sel;                           
  198.                         struct MOVIETRANS *ltransnode;
  199.                         struct MOVIETRANS *rtransnode;
  200.                         };
  201.  
  202. typedef struct      NAMERECORD {
  203.                         char name [NAMELENGTH];
  204.                         int count;
  205.                         SEL sel;
  206.                         struct NAMERECORD FAR *last_name_rec;
  207.                         struct NAMERECORD FAR *next_name_rec;
  208.                         };
  209.  
  210. typedef struct      YEARRECORD {
  211.                         char year [YEARLENGTH];
  212.                         int count;
  213.                         SEL sel;
  214.                         struct YEARRECORD FAR *last_year_rec;
  215.                         struct YEARRECORD FAR *next_year_rec;
  216.                         };
  217.  
  218. /*---------------------------------------------------------------------------*/
  219.  
  220. #pragma subtitle("Argument-type lists")
  221. #pragma page()
  222.  
  223. /*-------------------------------------------------- argument-type lists ----*/
  224.  
  225. /* 
  226.     An argument-type-list establishes the number and types of the
  227.     arguments to a function and causes the compiler to perform
  228.     type checking between the formal parameters and actual arguments
  229.     of a function each time it is used and to generate a warning in
  230.     case of inconsistency.
  231. */
  232. extern  void main(void );
  233. extern  void change_paths(void );
  234. extern  int check_paths(char *base_file_id,char *work_file_id);
  235. extern  void clear_screen(int foreground,int background);
  236. extern  void cur_size(int size);
  237. extern  void disp_rec(USHORT row,struct MOVIERECORD *rec_ptr);
  238. extern  void display(USHORT row, struct MOVIETRANS *trans_ptr);
  239. extern  void draw_box(char box_type,USHORT left_column,USHORT right_column,
  240.                       USHORT top_row,USHORT bottom_row);
  241. extern  void editLdata(char *data_string,int width);
  242. extern  void editRdata(char *data_string,int width);
  243. extern  void file_convert(char *base_file_id,char *work_file_id);
  244. extern  void file_con_menu(void );
  245. extern  void file_con_get_id(char *old_base_file_id);
  246. extern  int get_change(struct MOVIETRANS *trans1_ptr,
  247.                        struct MOVIETRANS *trans2_ptr,char *base_file_id);
  248. extern  int get_data(struct MOVIETRANS *trans_ptr);
  249. extern  int get_delete(struct MOVIETRANS *trans1_ptr,
  250.                        struct MOVIETRANS *trans2_ptr,char *base_file_id);
  251. extern  void get_form(char *form_ptr);
  252. extern  void get_loc(char *loc_ptr,char *loc_for);
  253. extern  void get_mpaa_code(char *mpaa_ptr);
  254. extern  void get_name(char *name_ptr,char *name_for);
  255. extern  void get_rating(char *rate_ptr);
  256. extern  void get_subject(char *subj_ptr);
  257. extern  void get_title(char *title_ptr);
  258. extern  void get_year(char *year_ptr);
  259. extern  int has_color(void );
  260. extern  int in_order(struct _iobuf *workf_ptr,struct _iobuf *basef_ptr,
  261.            struct MOVIETRANS *tree_ptr,struct MOVIETRANS *base_buff,int count);
  262. extern  void lbl_hp_box(struct _iobuf *print_pointer,int start_row,
  263.                        int start_column);
  264. extern  void lbl_hp_courier(struct _iobuf *print_pointer);
  265. extern  void lbl_hp_line_printer(struct _iobuf *print_pointer);
  266. extern  struct LABELDATA *lbl_hp_print(struct LABELNODE *lbltree_node,
  267.                                        struct _iobuf *print_pointer,
  268.                                        int run_number);
  269. extern  void lbl_hp_reset(struct _iobuf *print_pointer);
  270. extern  void lbl_hp_set_cursor(struct _iobuf *print_pointer,int row,int column);
  271. extern  int lbl_loc_comp(struct LABELNODE *loc_node1,
  272.                          struct LABELNODE *loc_node2);
  273. extern  void lbl_make_labels(char *base_file_id);
  274. extern  struct LABELDATA *lbl_print(struct LABELNODE *lbltree_node,
  275.                                     struct _iobuf *print_pointer,
  276.                                     int run_number);
  277. extern  struct LABELNODE *lbl_search(char *base_file_id,char *min_loc,
  278.                                      char *max_loc);
  279. extern  struct LABELNODE *lbl_tree_insert(struct LABELNODE *lbltree_root,
  280.                                           struct LABELNODE *new_node);
  281. extern  void main_menu(void );
  282. extern  void name_out(char *name_ptr);
  283. extern  char outopt(void );
  284. extern  char pause(void );
  285. extern  void print_rec(struct MOVIERECORD *rec_ptr,
  286.                        struct _iobuf *print_pointer);
  287. extern  char prnopt(void );
  288. extern  char qpause(void );
  289. extern  int rec_comp(struct MOVIERECORD *rec1,struct MOVIERECORD *rec2);
  290. extern  void search(char *base_file_id);
  291. extern  char search_key(struct MOVIERECORD *s_key_record);
  292. extern  void set_border(int color);
  293. extern  void set_cursor(int row,int column,int page);
  294. extern  void tally(char *base_file_id);
  295. extern  void tally_display (struct NAMERECORD far *dir_name_list,
  296.                             struct NAMERECORD far *star_name_list,
  297.                             struct YEARRECORD far *year_list,
  298.                             char *form_codes, int *form_counts,
  299.                             char *rating_codes, int *rating_counts,
  300.                             char *subj_codes, int *subj_counts,
  301.                             int total_movies);
  302. extern  struct NAMERECORD far *tally_list_name(char *new_name,
  303.                             struct NAMERECORD far *name_list);
  304. extern  struct YEARRECORD far *tally_list_year(char *new_year,
  305.                             struct YEARRECORD far *year_list);
  306. extern  void tally_sort(int sort_number,char *sort_codes,int *sort_counts);
  307. extern  int trans_comp(struct MOVIETRANS *trans1,struct MOVIETRANS *trans2);
  308. extern  int tree_display(struct MOVIETRANS *tree_ptr,int count);
  309. extern  struct MOVIETRANS *tree_insert(struct MOVIETRANS *tree_root,
  310.                                        struct MOVIETRANS *new_trans);
  311. extern  void trim(char *string_ptr);
  312. extern  struct MOVIETRANS *update(struct MOVIETRANS *root,char *base_file_id,
  313.                             char *work_file_id,struct MOVIETRANS *trans_buff);
  314. extern  int verify(void );
  315. extern  void welcome(void );
  316. extern  void whole_cat(char *base_file_id);
  317. extern  void window(int left_column,int right_column,int top_row,
  318.                     int bottom_row,int foreground,int background);
  319.  
  320. /*---------------------------------------------------------------------------*/
  321.                                        
  322. /*----------------------------------------- External Variable References ----*/
  323.  
  324. /* 
  325.     External reference declarations make a variable visible which is
  326.     either declared later in the same source file or which is known to
  327.     the linker as having been declared in another source file.
  328. */
  329.  
  330.                  /* external reference to global variables */
  331.  
  332.  
  333. extern char *subjects[];
  334. extern char *forms[];
  335. extern char *ratings[];
  336. extern char codes[];
  337.  
  338. /*---------------------------------------------------------------------------*/
  339.  
  340. /*-----------------------------------------------------------------------------
  341.                     Header for source file ends here.
  342. -----------------------------------------------------------------------------*/
  343. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ header ^^^^*/
  344.  
  345. #pragma subtitle("global declarations")
  346. #pragma page()
  347.  
  348.  
  349. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv globals vvvv*/
  350.  
  351. /*--------------------------------- External Level Variable Declarations ----*/
  352.  
  353. /*
  354.     Variables declared at the external level, i.e. outside a function, are
  355.     global, i.e. visible in all functions, throughout the remainder of the
  356.     source file and can be made visible earlier in the same source file or
  357.     in other source files through external reference declarations.
  358. */
  359.                    /*  global variable declarations */
  360.  
  361.  
  362.  
  363.        char *subjects[] = {
  364.  
  365.                                 "Action         ",
  366.                                 "Adult          ",
  367.                                 "Animated       ",
  368.                                 "Biographical   ",
  369.                                 "Caper          ",
  370.                                 "Contemporary   ",
  371.                                 "Courtroom      ",
  372.                                 "Crime          ",
  373.                                 "Dance          ",
  374.                                 "Detective      ",
  375.                                 "Disaster       ",
  376.                                 "Family         ",
  377.                                 "Futuristic     ",
  378.                                 "Gangster       ",
  379.                                 "Historical     ",
  380.                                 "Horror         ",
  381.                                 "International  ",
  382.                                 "Journalism     ",
  383.                                 "Military       ",
  384.                                 "Medical        ",
  385.                                 "Murder         ",
  386.                                 "Musical        ",
  387.                                 "Period         ",
  388.                                 "Police         ",
  389.                                 "Political      ",
  390.                                 "Prison         ",
  391.                                 "Psychological  ",
  392.                                 "Religious      ",
  393.                                 "Rock           ",
  394.                                 "Romantic       ",
  395.                                 "Science        ",
  396.                                 "Science-Fiction",
  397.                                 "Sex            ",
  398.                                 "Social         ",
  399.                                 "Sports         ",
  400.                                 "Supernatural   ",
  401.                                 "Suspense       ",
  402.                                 "Terror         ",
  403.                                 "War            ",
  404.                                 "Western        ",
  405.                                 "Youth          ",
  406.                                 "Miscellaneous  "
  407.                        };
  408.  
  409.        char *forms[] = {
  410.                                 "Adventure      ",
  411.                                 "Classic        ",
  412.                                 "Comedy         ",
  413.                                 "Comedy-drama   ",
  414.                                 "Compilation    ",
  415.                                 "Concert        ",
  416.                                 "Documentary    ",
  417.                                 "Docu-drama     ",
  418.                                 "Drama          ",
  419.                                 "Epic           ",
  420.                                 "Fantasy        ",
  421.                                 "Farce          ",
  422.                                 "Intrigue       ",
  423.                                 "Melodrama      ",
  424.                                 "Mystery        ",
  425.                                 "One-man-show   ",
  426.                                 "Opera          ",
  427.                                 "Revue          ",
  428.                                 "Romance        ",
  429.                                 "Satire         ",
  430.                                 "Spoof          ",
  431.                                 "Story          ",
  432.                                 "Thriller       ",
  433.                                 "Variety        " 
  434.                                 };
  435.  
  436.        char *ratings[] = {
  437.                                 "****  Excellent",
  438.                                 "***+  Very Good",
  439.                                 "***        Good",
  440.                                 "**+ Pretty Good",
  441.                                 "**         Fair",
  442.                                 "*+         Poor",
  443.                                 "*           Bad",
  444.                                 "+       Abysmal"
  445.                                 };
  446.  
  447.        char *mpaa_codes[] = {
  448.                                 "MPAA    G Rated",
  449.                                 "MPAA   PG Rated",
  450.                                 "MPAA PG13 Rated",
  451.                                 "MPAA    R Rated",
  452.                                 "MPAA    X Rated",
  453.                                 "MPAA  Not Rated",
  454.                                 };          
  455.  
  456.  
  457. char codes[CODENUMBER] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
  458.                           'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
  459.                           'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4',
  460.                           '5', '6', '7', '8', '9', '0', '#', '$', '%', '&',
  461.                           '!', '*'};
  462.  
  463.  
  464. /*---------------------------------------------------------------------------*/
  465.  
  466. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ globals ^^^^*/
  467.  
  468. #pragma subtitle("main()")
  469. #pragma page()
  470.  
  471. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv main vvvv*/
  472. /*----------------------------------------------------------------------------+
  473. |                                                                             |
  474. | SYNOPSIS                                                                    |
  475. | ~~~~~~~~                                                                    |
  476. |  #include <stdio.h>                                                         |
  477. |  #include <ctype.h>                                                         |
  478. |  #include <dos.h>                                                           |
  479. |  #include <string.h>                                                        |
  480. |  #include <direct.h>                                                        |
  481. |  #include <malloc.h>                                                        |
  482. |  #include <memory.h>                                                        |
  483. |  #include <time.h>                                                          |
  484. |  #include <sys\types.h>                                                     |
  485. |  #include <sys\stat.h>                                                      |
  486. |  #include <stdlib.h>                                                        |
  487. |  #include <os2.h>                                                           |
  488. |                                                                             |
  489. |  void main(void)                                                            |
  490. |                                                                             |
  491. | FUNCTION                                                                    |
  492. | ~~~~~~~~                                                                    |
  493. |   C defines main() as the entry point of the program.  Main() in this       |
  494. |   program is the main control module.  It performs certain initialization   |
  495. |   activities and then calls other principal modules in a while loop which   |
  496. |   cycles until the user requests exit.  At the beginning of each loop       |
  497. |   the main command menu is displayed and the user is prompted to enter      |
  498. |   a code for the function desired.  Switch selection then calls the         |
  499. |   appropriate routines according to the code entered by the user.           |
  500. |                                                                             |
  501. | RETURNS                                                                     |
  502. | ~~~~~~~                                                                     |
  503. |                                                                             |
  504. |   Nothing.                                                                  |
  505. |                                                                             |
  506. |                                                                             |
  507. | NOTES                                                                       |
  508. | ~~~~~                                                                       |
  509. |   Calls all other functions in the program, many of which use non-          |
  510. |   standard C extensions.                                                    |
  511. |                                                                             |
  512. |                                                                             |
  513. +----------------------------------------------------------------------------*/
  514. void main ()
  515.  
  516. {
  517.   char                  base_file_id [INPUTLENGTH];/*path & name of base file*/
  518.   char                  command = '\0';              /* current user command */
  519.   extern void           change_paths();           /* func changes file paths */
  520.   extern int            check_paths();     /* func asks user to verify paths */
  521.   extern void           clear_screen(); /* func to clear screen & set colors */
  522.   extern void           cur_size();                 /* func sets cursor size */
  523.   extern void           file_convert ();   /* func converts data file format */
  524.   extern int            get_change();    /* gets data for change transaction */
  525.   extern int            get_data();        /* func gets data for transaction */
  526.   extern int            get_delete();    /* gets data for delete transaction */
  527.   extern int            has_color();         /* func tests for color display */
  528.   extern void           lbl_make_labels();              /* func makes labels */
  529.   char                  input_command [INPUTLENGTH];    /* user input buffer */
  530.   extern void           main_menu();              /* func displays main menu */
  531.   extern char           pause();                   /* func to pause for user */
  532.   struct MOVIETRANS    *root = NULL;      /* root of transaction binary tree */
  533.   extern void           search();                 /* func searches base file */
  534.   extern void           set_border();    /* func to set display border color */
  535.   extern void           set_cursor();               /* func positions cursor */
  536.   extern void           tally();                   /* func tallys statistics */
  537.   extern int            tree_display(); /* func displays transactions in tree*/
  538.   struct MOVIETRANS    *tree_insert();       /* func to insert trans in tree */
  539.   extern void           trim();         /* func trims lead & trail whitespace*/
  540.   struct MOVIETRANS    *trans1_buff = NULL;         /* transaction work area */
  541.   struct MOVIETRANS    *trans2_buff = NULL;         /* transaction work area */
  542.   struct MOVIETRANS    *trans1_temp = NULL;         /* transaction work area */
  543.   struct MOVIETRANS    *trans2_temp = NULL;         /* transaction work area */
  544.   extern struct MOVIETRANS *update();              /* func updates base file */
  545.   extern void           welcome();         /* func for welecome user routine */
  546.   extern void           whole_cat();                  /* func prints catalog */
  547.   char                  work_file_id [INPUTLENGTH];/*path & name of work file*/
  548.  
  549.            /* start-up routines */
  550.                                                /* allocate memory to buffers */
  551.   trans1_buff = (struct MOVIETRANS *)calloc (1, sizeof (struct MOVIETRANS));
  552.   trans2_buff = (struct MOVIETRANS *)calloc (1, sizeof (struct MOVIETRANS));
  553.   set_border (BLACK);                                    /* set border color */
  554.   welcome();                                    /* call func to welcome user */
  555.   while (!(check_paths(base_file_id, work_file_id)))  /* verify file paths & */
  556.     change_paths ();                               /* change if not verified */
  557.  
  558.  
  559.           /* main processing loop */
  560.  
  561.   while (command != 'E')                        /* loop until exit command - */
  562.   {
  563.     main_menu();                                        /* display main menu */
  564.     gets (input_command);                                  /* get user input */
  565.     trim (input_command);                 /* trim whitespace from user input */
  566.     command = input_command [0];                      /* 1st char is command */
  567.     command = toupper (command);          /* make sure command is upper case */
  568.   
  569.     switch (command)              /* select action according to user command */
  570.     {
  571.       case 'A' :                                            /* if add code - */
  572.         
  573.         trans1_buff = (struct MOVIETRANS *)memset         /* zero out buffer */
  574.           ((char *)trans1_buff, '\0', sizeof(struct MOVIETRANS));
  575.         trans1_buff->transaction = command;          /* set transaction code */
  576.         if (get_data (trans1_buff))       /* call func to get data from user */
  577.         {                                                   /* if successful */
  578.           root = tree_insert (root, trans1_buff);    /* insert trans in tree */
  579.         }                                                     /* advise user */
  580.         break;                                 /* exit from switch selection */
  581.  
  582.       case 'C' :                                        /* if change command */
  583.                                                             /* clear buffers */
  584.         trans1_buff = (struct MOVIETRANS *)memset 
  585.           ((char *)trans1_buff, '\0', sizeof(struct MOVIETRANS));
  586.         trans2_buff = (struct MOVIETRANS *)memset
  587.           ((char *)trans2_buff, '\0', sizeof (struct MOVIETRANS));
  588.         trans1_buff->transaction = command;          /* set transaction code */
  589.         trans1_temp = trans1_buff;    /* use temp variables to pass pointers */
  590.         trans2_temp = trans2_buff;           /* (avoids bug in get_change()) */
  591.         if (get_change (trans1_temp, trans2_temp, base_file_id))
  592.         {        /* call func to get change data from user - if successful - */
  593.           root = tree_insert (root, trans1_buff);    /* insert trans in tree */
  594.           root = tree_insert (root, trans2_buff);   /* (del old,add changed) */
  595.         }                                                     /* advise user */
  596.         break;                                 /* exit from switch selection */
  597.  
  598.       case 'D' :                                           /* if delete code */
  599.                                                             /* clear buffers */
  600.         trans1_buff = (struct MOVIETRANS *)memset
  601.            ((char *)trans1_buff, '\0', sizeof(struct MOVIETRANS));
  602.         trans2_buff = (struct MOVIETRANS *)memset
  603.            ((char *)trans2_buff, '\0', sizeof (struct MOVIETRANS));
  604.         trans1_buff->transaction = command;          /* set transaction code */
  605.         if (get_delete (trans1_buff, trans2_buff, base_file_id))
  606.           {                           /* get record to be deleted - if found */
  607.           root = tree_insert (root, trans2_buff);    /* insert trans in tree */
  608.           }                                                   /* advise user */
  609.         break;
  610.       
  611.       case 'F' :                                  /* file conversion command */
  612.  
  613.         file_convert ( base_file_id, work_file_id);             /* call func */
  614.         break;
  615.             
  616.  
  617.       case 'L' :                                         /* label maker code */
  618.                                                 /* clear screen & set colors */
  619.         clear_screen (LWHITE, BLUE);             /* call func to make labels */
  620.         lbl_make_labels(base_file_id);
  621.         break;
  622.  
  623.       case 'R' :                             /* for review transactions code */
  624.  
  625.         tree_display (root, 0); /* call func to display current transactions */
  626.         VioSetCurPos (22,0,0);
  627.         printf ("End of current changes. ");                  /* advise user */
  628.         pause();                                            /* wait for user */
  629.         break;                                      /* exit switch selection */
  630.  
  631.       case 'S' :                                          /* for search code */
  632.  
  633.         search (base_file_id);                /* call func to conduct search */
  634.         break;                                 /* exit from switch selection */
  635.  
  636.       case 'T'  :                            /* for tally statistics command */
  637.  
  638.         clear_screen (LWHITE, BLACK);   /* clear screen & set display colors */
  639.         set_cursor (11,11,0);                             /* position cursor */
  640.         printf ("COMPILING STATISTICS ...");                  /* advise user */
  641.         tally (base_file_id);              /* call func to tally statistics  */
  642.         clear_screen (LWHITE, BLUE);    /* clear screen & set display colors */
  643.         break;                                      /* exit switch selection */
  644.  
  645.       case 'U' :                                  /* for update command code */
  646.  
  647.         root = update (root, base_file_id, work_file_id, trans1_buff);
  648.         break;
  649.  
  650.       case 'W' :                                /* for print catalog command */
  651.  
  652.         whole_cat(base_file_id);               /* call func to print catalog */
  653.         break;                                      /* exit switch selection */
  654.  
  655.       case 'E' :                                            /* for exit code */
  656.  
  657.         set_border (BLACK);
  658.         clear_screen (WHITE,BLACK);
  659.         break;                                 /* exit from switch selection */
  660.  
  661.       default  :              /* if no switch selected, code must be invalid */
  662.  
  663.         printf ("\nINVALID CODE\n");                            /* warn user */
  664.         pause();                                            /* wait for user */
  665.         break;                                      /* exit switch selection */
  666.     }  
  667.   }
  668. }   
  669.  
  670. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ main() ^^^^*/
  671.  
  672. #pragma subtitle("change_paths()")
  673. #pragma page()
  674.  
  675.  
  676. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv change_paths vvvv*/
  677. /*----------------------------------------------------------------------------+
  678. |                                                                             |
  679. | SYNOPSIS                                                                    |
  680. | ~~~~~~~~                                                                    |
  681. |   #include <stdio.h>                                                        |
  682. |   void change_paths(void)                                                   |
  683. |                                                                             |
  684. | FUNCTION                                                                    |
  685. | ~~~~~~~~                                                                    |
  686. |   Changes paths of base file and work file both in the strings              |
  687. |   passed by the calling routine and in the configuration file.              |
  688. |                                                                             |
  689. |                                                                             |
  690. | RETURNS                                                                     |
  691. | ~~~~~~~                                                                     |
  692. |   Nothing.                                                                  |
  693. |                                                                             |
  694. |                                                                             |
  695. |                                                                             |
  696. | NOTES                                                                       |
  697. | ~~~~~                                                                       |
  698. |   Calls clear_screen(), pause() and trim() functions.                       |
  699. |                                                                             |
  700. |                                                                             |
  701. |                                                                             |
  702. |                                                                             |
  703. |                                                                             |
  704. +----------------------------------------------------------------------------*/
  705.  
  706. void change_paths ()
  707.  
  708. {
  709.   USHORT        cbString;                               /* string byte count */
  710.   char         *char_buff;                                  /* string buffer */
  711.   char          base_path[INPUTLENGTH];                  /* base path string */
  712.   FILE         *cfg_file_ptr;                   /* ptr to configuration file */
  713.   extern void   clear_screen();                      /* func to clear screen */
  714.   HVIO          hvio = 0;                                    /* video handle */
  715.   extern void   set_border();              /* func sets display border color */
  716.   extern void   trim();                   /* func trims lead & trail whitesp */
  717.   char          work_path[INPUTLENGTH];                  /* work path string */
  718.  
  719.   char_buff = (char *)calloc (1, 0x100);
  720.   clear_screen (LWHITE,BLACK);                  /* clear screen & set colors */
  721.   window (0,79,0,20,LWHITE,BLUE);
  722.   window (6,78,9,14,BLACK,BLACK);
  723.   window (4,76,8,13,BLACK,WHITE);
  724.   set_border (BLUE);                              /* set screen border color */
  725.   VioSetCurPos (22,0,hvio);                               /* position cursor */
  726.      /* get changes from user */
  727.     
  728.   cfg_file_ptr = fopen ("VIDEOCAT.CFG", "w");   /* open config file for write*/
  729.   if (cfg_file_ptr == NULL)
  730.   {
  731.      printf (" Error in attempting to open new configuration file.\n");
  732.      pause();
  733.      VioWrtNChar(" ",80,22,0,hvio);
  734.      VioWrtNChar(" ",80,23,0,hvio);
  735.      VioSetCurPos (22,0,hvio);
  736.   }
  737.   sprintf(char_buff,
  738.    " The permanent data base file must be on a hard or floppy disk path.   ");
  739.   cbString = (USHORT)strlen(char_buff);
  740.   VioWrtCharStr (char_buff,cbString,9,6,hvio);
  741.   sprintf(char_buff,
  742.    " The temporary data file may be on a hard, floppy or RAM disk (VDISK)  ");
  743.   cbString = (USHORT)strlen(char_buff);
  744.   VioWrtCharStr (char_buff,cbString,10,6,hvio);
  745.   sprintf(char_buff,
  746.    " path.  Putting the temporary data file on RAM disk will improve speed ");
  747.   cbString = (USHORT)strlen(char_buff);
  748.   VioWrtCharStr (char_buff,cbString,11,6,hvio);
  749.   sprintf(char_buff,
  750.    " but may make it unavilable as a backup to the permanent data file.    ");
  751.   cbString = (USHORT)strlen(char_buff);
  752.   VioWrtCharStr (char_buff,cbString,12,6,hvio);
  753.  
  754.   printf
  755.     (" Enter path for permanent data base file (must be a floppy or\n");
  756.   printf 
  757.     (" hard disk path) -> ");
  758.   gets (base_path);                             /* get base path from console*/
  759.   trim (base_path);                                       /* trim whitespace */
  760.   strupr (base_path);
  761.   while (base_path[strlen(base_path) -1] == '\\')/* strip trailing backslash */
  762.     base_path [strlen(base_path) -1] = '\0';
  763.   if ((fputs(base_path, cfg_file_ptr)) == EOF)  /* write base path to config */
  764.   {
  765.      printf (" Error in writing to configuration file.\n");
  766.      pause();
  767.      VioWrtNChar(" ",80,22,0,hvio);
  768.      VioWrtNChar(" ",80,23,0,hvio);
  769.      VioSetCurPos (22,0,hvio);
  770.   }
  771.   if ((fputs("\n", cfg_file_ptr)) == EOF)         /* - write newline to file */
  772.   {
  773.      printf (" Error in writing to configuration file.\n");
  774.      pause();
  775.      VioWrtNChar(" ",80,22,0,hvio);
  776.      VioWrtNChar(" ",80,23,0,hvio);
  777.      VioSetCurPos (22,0,hvio);
  778.   }
  779.   VioWrtNChar(" ",80,22,0,hvio);
  780.   VioWrtNChar(" ",80,23,0,hvio);
  781.   VioWrtNChar(" ",80,24,0,hvio);
  782.   VioSetCurPos(22,0,hvio);
  783.   printf                                        /* prompt user for work path */
  784.     (" Enter path for temporary data file (may be \n");
  785.   printf 
  786.     (" RAM, floppy or hard path) -> ");
  787.   gets (work_path);                                    /* read user response */
  788.   trim (work_path);                                       /* trim whitespace */
  789.   strupr (work_path);
  790.   VioWrtNChar(" ",80,22,0,hvio);
  791.   VioWrtNChar(" ",80,23,0,hvio);
  792.   VioWrtNChar(" ",80,24,0,hvio);
  793.   VioSetCurPos(22,0,hvio);
  794.   while (work_path[strlen(work_path) -1] == '\\')/* strip trailing backslash */
  795.     work_path [strlen(work_path) -1] = '\0';
  796.   if ((fputs(work_path, cfg_file_ptr)) == EOF)  /* write work path to config */
  797.   {
  798.      printf (" Error in writing to configuration file.\n");
  799.      pause();
  800.      VioWrtNChar(" ",80,22,0,hvio);
  801.      VioWrtNChar(" ",80,23,0,hvio);
  802.      VioSetCurPos (22,0,hvio);
  803.   }
  804.   VioWrtNChar(" ",80,22,0,hvio);
  805.   VioWrtNChar(" ",80,23,0,hvio);
  806.   VioWrtNChar(" ",80,24,0,hvio);
  807.   VioSetCurPos(22,0,hvio);
  808.   if ((fputs("\n", cfg_file_ptr)) == EOF)         /* - write newline to file */
  809.   {
  810.      printf (" Error in writing to configuration file.\n");
  811.      pause();
  812.      VioWrtNChar(" ",80,22,0,hvio);
  813.      VioWrtNChar(" ",80,23,0,hvio);
  814.      VioSetCurPos (22,0,hvio);
  815.   }
  816.   fclose (cfg_file_ptr);                                /* close config file */
  817.   set_border (BLACK);
  818.   free (char_buff);
  819. }
  820.  
  821. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ change_paths ^^^^*/
  822.  
  823. #pragma subtitle("check_paths()")
  824. #pragma page()
  825.  
  826. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv check_paths vvvv*/
  827.  
  828. /*----------------------------------------------------------------------------+
  829. |                                                                             |
  830. | SYNOPSIS                                                                    |
  831. | ~~~~~~~~                                                                    |
  832. |   #include <stdio.h>                                                        |
  833. |   #include <string.h>                                                       |
  834. |   #include <direct.h>                                                       |
  835. |   int check_paths(char *base_file_id, char *work_file_id);                  |
  836. |                                                                             |
  837. |  FUNCTION                                                                   |
  838. |  ~~~~~~~~                                                                   |
  839. |   Checks DOS paths for the files base_file_id and work_file_id.             |
  840. |   Reads initial settings from configuration file; if not present            |
  841. |   it creates a configuration file using the path of the current             |
  842. |   directory.  Displays the paths and asks the user if changes are           |
  843. |   desired; if so the function change_paths() is called.  After any          |
  844. |   path changes have been made, it checks for the presence of the            |
  845. |   base and work files and attempts to create them if not found.  If         |
  846. |   the files cannot be found or made, the user is prompted for further       |
  847. |   path changes.                                                             |
  848. |                                                                             |
  849. |                                                                             |
  850. | RETURNS                                                                     |
  851. | ~~~~~~~                                                                     |
  852. |   1 if successfully completed; 0 if paths invalid.                          |
  853. |                                                                             |
  854. | NOTES                                                                       |
  855. | ~~~~~                                                                       |
  856. |   Uses getcwd(), an MSC extension which may not be portable accross         |
  857. |   compilers and operating systems.                                          |
  858. |                                                                             |
  859. +----------------------------------------------------------------------------*/
  860.  
  861.  
  862. int check_paths(base_file_id, work_file_id)
  863.  
  864.   char     *base_file_id;                             /* ptr to base file id */
  865.   char     *work_file_id;                             /* ptr to work file id */
  866.  
  867. {
  868.   USHORT        cbString;                               /* string byte count */
  869.   char         *char_buff;                                  /* string buffer */
  870.   char          base_path [INPUTLENGTH];                /* path to base file */
  871.   FILE         *basef_ptr;                           /* pointer to base file */
  872.   char         *cdir_ptr;                    /* pointer to current directory */
  873.   extern void   clear_screen();                      /* func to clear screen */
  874.   FILE         *cfg_file_ptr;                          /* ptr to config file */
  875.   HVIO          hvio = 0;                                    /* video handle */
  876.   extern char   pause();                             /* func pauses for user */
  877.   char          response [INPUTLENGTH];                     /* user response */
  878.   extern void   set_border();              /* func sets display border color */
  879.   extern void   trim();                             /* func trims whitespace */
  880.   FILE         *workf_ptr;                              /* work file pointer */
  881.   char          work_path [INPUTLENGTH];               /* path for work file */
  882.  
  883.   
  884.             /* open configuration file for read */
  885.             /* if not found, create it using current path */
  886.             
  887.  
  888.   char_buff = (char *) calloc (1, 0x100);
  889.   clear_screen (LWHITE,BLACK);                  /* clear screen & set colors */
  890.   window (0,79,0,20,LWHITE,BLUE);
  891.   window (6,78,9,14,BLACK,BLACK);
  892.   window (4,76,8,13,BLACK,WHITE);
  893.   set_border (BLUE);                              /* set screen border color */
  894.   VioSetCurPos (22,0,hvio);                               /* position cursor */
  895.                 
  896.                
  897.                
  898.                
  899.   cfg_file_ptr = fopen ("VIDEOCAT.CFG", "r");       /* attempt open for read */
  900.   if (cfg_file_ptr == NULL)                             /* if unsuccessful - */
  901.   {  
  902.     sprintf (char_buff,"Configuration file not found; creating new one.");
  903.     cbString = (USHORT)strlen(char_buff);
  904.     VioWrtCharStr (char_buff,cbString,11,9,hvio);
  905.     VioSetCurPos (22,0,hvio);
  906.     pause();                                               /* pause for user */
  907.     cfg_file_ptr = fopen ("VIDEOCAT.CFG", "w");         /* - open for write  */
  908.     if (cfg_file_ptr == NULL)
  909.     {
  910.        printf (" Error in attempting to open new configuration file.\n");
  911.        pause();
  912.        VioWrtNChar(" ",80,22,0,hvio);
  913.        VioWrtNChar(" ",80,23,0,hvio);
  914.        VioSetCurPos (22,0,hvio);
  915.     }
  916.     cdir_ptr = getcwd(NULL,80);
  917.     while (cdir_ptr[strlen(cdir_ptr) -1] == '\\')/* strip trailing backslash */
  918.       cdir_ptr [strlen(cdir_ptr) -1] = '\0';
  919.     if ((fputs(cdir_ptr, cfg_file_ptr)) == EOF)           /* - write to file */
  920.     {
  921.        printf (" Error in writing to configuration file.\n");
  922.        pause();
  923.        VioWrtNChar(" ",80,22,0,hvio);
  924.        VioWrtNChar(" ",80,23,0,hvio);
  925.        VioSetCurPos (22,0,hvio);
  926.     }
  927.     if ((fputs("\n", cfg_file_ptr)) == EOF)       /* - write newline to file */
  928.     {
  929.        printf (" Error in writing to configuration file.\n");
  930.        pause();
  931.        VioWrtNChar(" ",80,22,0,hvio);
  932.        VioWrtNChar(" ",80,23,0,hvio);
  933.        VioSetCurPos (22,0,hvio);
  934.     }
  935.     if ((fputs(cdir_ptr, cfg_file_ptr)) == EOF)   /* - write cur. path again */
  936.     {
  937.        printf (" Error in writing to configuration file.\n");
  938.        pause();
  939.        VioWrtNChar(" ",80,22,0,hvio);
  940.        VioWrtNChar(" ",80,23,0,hvio);
  941.        VioSetCurPos (22,0,hvio);
  942.     }
  943.     if ((fputs("\n", cfg_file_ptr)) == EOF)       /* - write another newline */
  944.     {
  945.        printf (" Error in writing to configuration file.\n");
  946.        pause();
  947.        VioWrtNChar(" ",80,22,0,hvio);
  948.        VioWrtNChar(" ",80,23,0,hvio);
  949.        VioSetCurPos (22,0,hvio);
  950.     }
  951.     fclose (cfg_file_ptr);                        /* - close config file     */
  952.     free ((char *)cdir_ptr);                      /* - free pointer          */
  953.     VioWrtNChar(" ",80,11,0,hvio);
  954.   }
  955.     /* read paths for base & work files from config file */
  956.     
  957.   cfg_file_ptr = fopen ("VIDEOCAT.CFG", "r");     /* - open config for read  */
  958.   fgets (base_path, INPUTLENGTH, cfg_file_ptr);   /* read path for base file */
  959.   trim (base_path);                                  /* trim whitespace (\n) */
  960.   fgets (work_path, INPUTLENGTH, cfg_file_ptr);   /* read path for work file */
  961.   trim (work_path);                                  /* trim whitespace (\n) */
  962.   fclose (cfg_file_ptr);                                /* close config file */
  963.  
  964.     /* advise user of current paths */
  965.     
  966.   sprintf(char_buff,"          Current Disk Drive Configuration");
  967.   cbString = (USHORT)strlen(char_buff);
  968.   VioWrtCharStr (char_buff,cbString,9,15,hvio);
  969.   sprintf(char_buff,"Permanent data base file is on path  %s", base_path);
  970.   cbString = (USHORT)strlen(char_buff);
  971.   VioWrtCharStr (char_buff,cbString,11,9,hvio);
  972.   sprintf(char_buff,"Temporary work files will be on path %s", work_path);
  973.   cbString = (USHORT)strlen(char_buff);
  974.   VioWrtCharStr (char_buff,cbString,12,9,hvio);
  975.  
  976.         /* find out if user wants to change paths */
  977.         
  978.   VioWrtNChar(" ",80,22,0,hvio);
  979.   VioWrtNChar(" ",80,23,0,hvio);
  980.   VioWrtNChar(" ",80,24,0,hvio);
  981.   VioSetCurPos(22,0,hvio);
  982.   printf                                                      /* prompt user */
  983.    (" Do you wish to change the current path configuration? (Y/N) -> ");
  984.   gets (response);                                      /* get user response */
  985.   trim (response);                          /* trim whitespace from response */
  986.   if ((response[0] == 'Y') || (response[0] == 'y'))           /* if Y or y - */
  987.   {
  988.     fcloseall();                                          /* close all files */
  989.     return 0;                                                    /* return 0 */
  990.   }
  991.         /* attempt to open base file */
  992.         /* attempt to create if it does not exist */
  993.         /* warn user if unsuccessful */
  994.         
  995.   strcpy (base_file_id, base_path);                             /* copy path */
  996.   strcat (base_file_id, "\\BASEFIL5.DAT");                 /* append file id */
  997.   basef_ptr = fopen (base_file_id, "r");                    /* open for read */
  998.   VioWrtNChar(" ",80,22,0,hvio);
  999.   VioWrtNChar(" ",80,23,0,hvio);
  1000.   VioWrtNChar(" ",80,24,0,hvio);
  1001.   VioSetCurPos(22,0,hvio);
  1002.   if (basef_ptr == NULL)                                    /* if open error */
  1003.   {                                                         /* - advise user */
  1004.     printf (" Base file not found; creating new one.\n");
  1005.     pause();
  1006.     basef_ptr = fopen (base_file_id, "w");   /* - attempt to create new file */
  1007.     if (basef_ptr == NULL)                            /* - if unsuccessful - */
  1008.     {
  1009.       printf (" Error in opening new base file.\n");
  1010.       pause();
  1011.       fcloseall();                                        /* close all files */
  1012.       return 0;                                                  /* return 0 */
  1013.     }
  1014.   }
  1015.   fclose (basef_ptr);
  1016.  
  1017.         /* attempt to open work file */
  1018.         /* attempt to create if it does not exist */
  1019.         /* warn user if unsuccessful */
  1020.         
  1021.   VioWrtNChar(" ",80,22,0,hvio);
  1022.   VioWrtNChar(" ",80,23,0,hvio);
  1023.   VioWrtNChar(" ",80,24,0,hvio);
  1024.   VioSetCurPos(22,0,hvio);
  1025.   strcpy (work_file_id, work_path);                             /* copy path */
  1026.   strcat (work_file_id, "\\WORKFILE.DAT");                 /* append file id */
  1027.   workf_ptr = fopen (work_file_id, "r");    /* attempt to open existing file */
  1028.   if (workf_ptr == NULL)                                  /* if open error - */
  1029.   {                                                           /* - warn user */
  1030.     printf (" Work file not found; creating new one.\n");
  1031.     pause();
  1032.     workf_ptr = fopen (work_file_id, "w");     /* - attempt to open new file */
  1033.     if (workf_ptr == NULL)                                /* - if open error */
  1034.     {
  1035.       printf (" Error in opening new work file.\n");            /* warn user */
  1036.       pause();
  1037.       fcloseall();                                        /* close all files */
  1038.       return 0;                                                  /* return 0 */
  1039.     }
  1040.   }
  1041.   fclose (workf_ptr);
  1042.  
  1043.   cfg_file_ptr = fopen ("VIDEOCAT.CFG", "r");     /* - open config for read  */
  1044.   basef_ptr = fopen (base_file_id, "r");                    /* open for read */
  1045.   workf_ptr = fopen (work_file_id, "r");    /* attempt to open existing file */
  1046.   if ((cfg_file_ptr != NULL)
  1047.      && (basef_ptr != NULL)
  1048.      && (workf_ptr != NULL))
  1049.   {  
  1050.     fclose (cfg_file_ptr);
  1051.     fclose (basef_ptr);
  1052.     fclose (workf_ptr);
  1053.     return 1;
  1054.   }
  1055.   else
  1056.   {
  1057.     fclose (cfg_file_ptr);
  1058.     fclose (basef_ptr);
  1059.     fclose (workf_ptr);
  1060.     return 0;
  1061.   }
  1062.   free (char_buff);
  1063.  
  1064. }
  1065.  
  1066. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ check_paths ^^^^*/
  1067.  
  1068. #pragma subtitle("clear_screen()")
  1069. #pragma page()
  1070.  
  1071.  
  1072. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv clear_screen vvvv*/
  1073.  
  1074. /*----------------------------------------------------------------------------+
  1075. |                                                                             |
  1076. | SYNOPSIS                                                                    |
  1077. | ~~~~~~~~                                                                    |
  1078. | #include <stdio.h>                                                          |
  1079. | #include <os2.h>                                                            |
  1080. | void clear_screen (int foreground, int background)                          |
  1081. |                                                                             |
  1082. |                                                                             |
  1083. | FUNCTION                                                                    |
  1084. | ~~~~~~~~                                                                    |
  1085. |   Clears screen, sets specified video attributes (foreground and            |
  1086. |   background colors for blank lines) and homes cursor.                      |
  1087. |                                                                             |
  1088. | RETURNS                                                                     |
  1089. | ~~~~~~~                                                                     |
  1090. |   Nothing.                                                                  |
  1091. |                                                                             |
  1092. |                                                                             |
  1093. |                                                                             |
  1094. | NOTES                                                                       |
  1095. | ~~~~~                                                                       |
  1096. |   Uses VioScrollDn and VioSetCurPos, MSC extensions which may not be        |
  1097. |   portable accross operating systems and compilers.                         |
  1098. |                                                                             |
  1099. |                                                                             |
  1100. +----------------------------------------------------------------------------*/
  1101.  
  1102. void clear_screen (foreground, background)
  1103.  
  1104. int foreground, background;
  1105.  
  1106. {
  1107.  
  1108.   int           attribute;                          /* video color attribute */
  1109.   USHORT          usTopRow = 0;                                     /* top row */
  1110.   USHORT        usLeftCol = 0;                                /* left column */
  1111.   USHORT        usBotRow = 24;                                 /* bottom row */
  1112.   USHORT        usRightCol = 79;                             /* right column */
  1113.   USHORT        cbLines = 25;                       /* number of blank lines */
  1114.   BYTE          bCell[2];                                   /* cell to write */
  1115.   HVIO          hvio = 0;                                    /* video handle */
  1116.   
  1117.   VioSetCurPos (usTopRow, usLeftCol,hvio);                    /* home cursor */
  1118.              
  1119.  
  1120.         /* set space character and color attribute byte for blank lines */
  1121.        
  1122.   bCell[0] = 0x20;                                        /* space character */
  1123.  
  1124.   if (has_color())                                              /* attribute */
  1125.     attribute = (0x10 * background) + foreground;
  1126.   else attribute = 0x7;
  1127.  
  1128.   bCell[1] = (BYTE)attribute;                    /* character attribute cell */
  1129.  
  1130.             /* clear screen and set colors */
  1131.  
  1132.   VioScrollDn (usTopRow, usLeftCol, usBotRow, usRightCol, cbLines, 
  1133.                   bCell, hvio);             
  1134.  
  1135.  
  1136. }
  1137.  
  1138. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ clear_screen ^^^^*/
  1139.  
  1140. #pragma subtitle("cur_size()")
  1141. #pragma page()
  1142.  
  1143. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv cur_size vvvv*/
  1144.  
  1145. /*----------------------------------------------------------------------------+
  1146. |                                                                             |
  1147. | SYNOPSIS                                                                    |
  1148. | ~~~~~~~~                                                                    |
  1149. |   #include <dos.h>                                                          |
  1150. |   void cur_size (int size)                                                  |
  1151. |                                                                             |
  1152. | FUNCTION                                                                    |
  1153. | ~~~~~~~~                                                                    |
  1154. |   This version sets the cursor either off or to normal size.  In future     |
  1155. |   versions it may also make other changes.                                  |
  1156. |                                                                             |
  1157. | RETURNS                                                                     |
  1158. | ~~~~~~~                                                                     |
  1159. |   Nothing.                                                                  |
  1160. |                                                                             |
  1161. |                                                                             |
  1162. |                                                                             |
  1163. | NOTES                                                                       |
  1164. | ~~~~~                                                                       |
  1165. |   This function uses VioGetCurType and VioSetCurType, MSC extensions        |
  1166. |   which may not be portable accross compilers and operating systems.        |
  1167. |                                                                             |
  1168. |                                                                             |
  1169. +----------------------------------------------------------------------------*/
  1170.  
  1171. void cur_size (size)                                      /* set cursor size */
  1172.  
  1173.   int               size;                                       /* size code */
  1174.  
  1175. {
  1176.  
  1177.   VIOCURSORINFO          viociCursor;
  1178.   HVIO                    hvio = 0;
  1179.   
  1180.   VioGetCurType (&viociCursor, hvio);
  1181.   
  1182.   if (size == CURSOFF)
  1183.     viociCursor.attr = 0xFFFF;
  1184.   else
  1185.     viociCursor.attr = 0;
  1186.     
  1187.   VioSetCurType (&viociCursor, hvio);
  1188.   
  1189.  
  1190. }
  1191.  
  1192. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cur_size   ^^^^*/
  1193.  
  1194. #pragma subtitle("disp_rec()")
  1195. #pragma page()
  1196.  
  1197. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv disp_rec vvvv*/
  1198. /*----------------------------------------------------------------------------+
  1199. |                                                                             |
  1200. | SYNOPSIS                                                                    |
  1201. | ~~~~~~~~                                                                    |
  1202. |   #include <stdio.h>                                                        |
  1203. |   #include <string.h>                                                       |
  1204. |   disp_rec (struct MOVIERECORD *rec_ptr)                                    |
  1205. |                                                                             |
  1206. | FUNCTION                                                                    |
  1207. | ~~~~~~~~                                                                    |
  1208. |   Displays the data contained in the record pointed to by rec_ptr           |
  1209. |   on the video display.                                                     |
  1210. |                                                                             |
  1211. |                                                                             |
  1212. | RETURNS                                                                     |
  1213. | ~~~~~~~                                                                     |
  1214. |   Nothing.                                                                  |
  1215. |                                                                             |
  1216. |                                                                             |
  1217. |                                                                             |
  1218. | NOTES                                                                       |
  1219. | ~~~~~                                                                       |
  1220. |   Uses a number of functions defined in videocat.c.  All use only           |
  1221. |   ANSI standard functions and should be portable.                           |
  1222. |                                                                             |
  1223. |                                                                             |
  1224. |                                                                             |
  1225. |                                                                             |
  1226. +----------------------------------------------------------------------------*/
  1227.  
  1228. void disp_rec (row, rec_ptr)
  1229.  
  1230.   USHORT row;  /* screen row */
  1231.   struct MOVIERECORD  *rec_ptr; /* ptr to a record */
  1232.  
  1233.  
  1234. {
  1235.   USHORT                cbString;                       /* string byte count */
  1236.   char                 *char_buff;                          /* string buffer */
  1237.   int                   count;                                    /* counter */
  1238.   HVIO                  hvio = 0;                            /* video handle */
  1239.   extern void           name_out();             /* func converts name format */
  1240.   extern void           trim();           /* func trims lead & trail whitesp */
  1241.   char                  star1_disp [INPUTLENGTH];   /*-----------------------*/
  1242.   char                  star2_disp [INPUTLENGTH];   /*  buffers in which the */
  1243.   char                  star3_disp [INPUTLENGTH];   /*  various elements in  */
  1244.   char                  dir_disp   [INPUTLENGTH];   /*  a MOVIETRANS struct  */
  1245.   char                  subj_disp  [INPUTLENGTH];   /*  are converted from   */
  1246.   char                  form_disp  [INPUTLENGTH];   /*  record format to a   */
  1247.   char                  type_disp  [INPUTLENGTH];   /*  display format.      */
  1248.   char                  rating_disp[INPUTLENGTH];   /*-----------------------*/
  1249.   char                  mpaa_disp  [INPUTLENGTH];
  1250.  
  1251.  
  1252.   char_buff = (char *) calloc (1, 0x100);
  1253.   strcpy (star1_disp, rec_ptr->star1);                    /* get star1  name */
  1254.   name_out (star1_disp);                          /* and convert for display */
  1255.  
  1256.   strcpy (star2_disp, rec_ptr->star2);                    /* get star2  name */
  1257.   name_out (star2_disp);                          /* and convert for display */
  1258.  
  1259.   strcpy (star3_disp, rec_ptr->star3);                    /* get star3  name */
  1260.   name_out (star3_disp);                          /* and convert for display */
  1261.  
  1262.   strcpy (dir_disp, rec_ptr->director);                 /* get director name */
  1263.   name_out (dir_disp);                            /* and convert for display */
  1264.   while (strlen (dir_disp) < 24)                /* pad director display name */
  1265.     strcat (dir_disp, " ");                          /* with trailing blanks */
  1266.   
  1267.   for (count = 0; count < CODENUMBER; count++)       /* look up subject code */
  1268.     if (rec_ptr->subject == codes [count])                 /* if found, copy */
  1269.           strcpy (subj_disp, subjects [count]);                /*  subject   */
  1270.   trim (subj_disp);                                          /* trim subject */
  1271.  
  1272.   for (count = 0; count < FORMNUMBER; count++)       /* look up form code    */
  1273.     if (rec_ptr->form == codes [count])                  /* if found, copy   */
  1274.       strcpy (form_disp, forms [count]);          /* corresponding form      */
  1275.   trim (form_disp);                                  /* trim form            */
  1276.   
  1277.   strcpy (type_disp, subj_disp);             /* copy subject to type buffer  */
  1278.       strcat (type_disp, " ");               /* append 1 blank space to type */
  1279.   strcat (type_disp, form_disp);             /* append form to type buffer   */
  1280.   while (strlen (type_disp) < 26)            /* pad type bufer with trailing */
  1281.     strcat (type_disp, " ");                 /* blanks to width 26           */
  1282.  
  1283.   strcpy (mpaa_disp, " ");                       /* initialize mpaa as blank */
  1284.   for (count = 0; count < MPAANUMBER; count++)       /* look up mpaa    code */
  1285.     if (rec_ptr->mpaa_code == codes [count])               /* if found, copy */
  1286.           strcpy (mpaa_disp, mpaa_codes [count]);              /*  mpaa      */
  1287.   trim (mpaa_disp);                                          /* trim mpaa    */
  1288.   while (strlen (mpaa_disp) < 20)            /* pad type bufer with trailing */
  1289.     strcat (mpaa_disp, " ");                 /* blanks to width 20           */
  1290.  
  1291.  
  1292.   for (count = 0; count < RATINGNUMBER; count++)         /* look up rating   */
  1293.     if (rec_ptr->rating == codes [count])                  /* if found copy  */
  1294.       strcpy (rating_disp, ratings [count]);         /* corresponding rating */
  1295.   trim (rating_disp);
  1296.  
  1297.                 /* print data in display format */
  1298.  
  1299.   sprintf (char_buff,      BLANK_LINE);
  1300.   cbString = (USHORT)strlen(char_buff);                    /* get byte count */
  1301.   VioWrtCharStr(char_buff,cbString,row,8,hvio);           /* write to screen */
  1302.   sprintf (char_buff,"%s               [%s]",
  1303.              rec_ptr->title, rec_ptr->year); 
  1304.   cbString = (USHORT)strlen(char_buff);                    /* get byte count */
  1305.   VioWrtCharStr(char_buff,cbString,row,8,hvio);           /* write to screen */
  1306.  
  1307.   sprintf (char_buff,"%s", BLANK_LINE);
  1308.   cbString = (USHORT)strlen(char_buff);                    /* get byte count */
  1309.   VioWrtCharStr(char_buff,cbString,(row + 1),8,hvio);     /* write to screen */
  1310.   sprintf (char_buff,"%s%s%s", type_disp, mpaa_disp, rating_disp);
  1311.   cbString = (USHORT)strlen(char_buff);                    /* get byte count */
  1312.   VioWrtCharStr(char_buff,cbString,(row + 1),8,hvio);     /* write to screen */
  1313.  
  1314.   sprintf (char_buff,"%s", BLANK_LINE);
  1315.   cbString = (USHORT)strlen(char_buff);                    /* get byte count */
  1316.   VioWrtCharStr(char_buff,cbString,(row + 2),8,hvio);     /* write to screen */
  1317.   sprintf (char_buff,"Starring: %s, %s, %s", star1_disp, star2_disp,
  1318.      star3_disp);
  1319.   cbString = (USHORT)strlen(char_buff);                    /* get byte count */
  1320.   VioWrtCharStr(char_buff,cbString,(row + 2),8,hvio);     /* write to screen */
  1321.                                            
  1322.   sprintf (char_buff,"%s", BLANK_LINE);
  1323.   cbString = (USHORT)strlen(char_buff);                    /* get byte count */
  1324.   VioWrtCharStr(char_buff,cbString,(row + 3),8,hvio);     /* write to screen */
  1325.   sprintf (char_buff,"Director: %s Cassette: %s Index: %s",
  1326.       dir_disp, rec_ptr->loc1, rec_ptr->loc2);
  1327.   cbString = (USHORT)strlen(char_buff);                    /* get byte count */
  1328.   VioWrtCharStr(char_buff,cbString,(row + 3),8,hvio);     /* write to screen */
  1329.  
  1330.   free (char_buff);
  1331. }
  1332.  
  1333. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ disp_rec ^^^^*/
  1334.  
  1335. #pragma subtitle("display()")
  1336. #pragma page()
  1337.  
  1338. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv display vvvv*/
  1339. /*----------------------------------------------------------------------------+
  1340. |                                                                             |
  1341. | SYNOPSIS                                                                    |
  1342. | ~~~~~~~~                                                                    |
  1343. |   #include <stdio.h>                                                        |
  1344. |   #include <os2.h>                                                          |
  1345. |   display (struct MOVIETRANS *trans_ptr)                                    |
  1346. |                                                                             |
  1347. | FUNCTION                                                                    |
  1348. | ~~~~~~~~                                                                    |
  1349. |   Displays a transaction, indicating type (add, change or delete)           |
  1350. |   and displaying the content of the record.                                 |
  1351. |                                                                             |
  1352. | RETURNS                                                                     |
  1353. | ~~~~~~~                                                                     |
  1354. |   Nothing.                                                                  |
  1355. |                                                                             |
  1356. |                                                                             |
  1357. | NOTES                                                                       |
  1358. | ~~~~~                                                                       |
  1359. |                                                                             |
  1360. |   Uses VioGetCurPos and VioWrtCharStr, MSC extensions which may not         |
  1361. |   be portable accross compilers and operating systems.                      |
  1362. |                                                                             |
  1363. |                                                                             |
  1364. +----------------------------------------------------------------------------*/
  1365.  
  1366. void display (row, trans_ptr)                /* displays content of a record */
  1367.  
  1368.   USHORT               row;                      /* row for start of display */
  1369.   struct MOVIETRANS   *trans_ptr;                /* pointer to a transaction */
  1370.  
  1371. {
  1372.   char                 *buffer;                 /* storage buffer for output */
  1373.   USHORT                cbString;               /* length of string in bytes */
  1374.   extern void           disp_rec(); /* function to display content of record */
  1375.   HVIO                  hvio = 0;                            /* video handle */
  1376.   struct MOVIERECORD   *rec_ptr;              /* pointer to record structure */
  1377.   USHORT                usColumn;              /* starting position (column) */
  1378.   USHORT                usRow;                    /* starting position (row) */
  1379.  
  1380.   buffer = (char *) calloc (1, 0x100);
  1381.   printf ("\n");                              /* advance cursor to next line */
  1382.  
  1383.   switch (trans_ptr->transaction) /* print transaction description to buffer */
  1384.     {                                  /* selected by trans_ptr->transaction */
  1385.     case 'A':  sprintf (buffer, "ADD");
  1386.                break;
  1387.     case 'C':  sprintf (buffer, "CHANGE");
  1388.                break;
  1389.     case 'D':  sprintf (buffer, "DELETE");
  1390.                break;
  1391.     }
  1392.  
  1393.   VioGetCurPos (&usRow, &usColumn, hvio);             /* get cursor position */
  1394.   cbString = (USHORT)strlen (buffer);                /* get length of string */
  1395.   VioWrtCharStr (buffer, cbString, row, 0, hvio);         /* write to screen */
  1396.     
  1397.   rec_ptr = &trans_ptr->moviedata;                  /* get pointer to record */
  1398.   disp_rec ((row + 1), rec_ptr);          /* call function to display record */
  1399.   free (buffer); 
  1400. }
  1401.  
  1402. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ display ^^^^*/
  1403.  
  1404. #pragma subtitle("draw_box()")
  1405. #pragma page()
  1406.  
  1407. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv draw_box vvvv*/
  1408. /*----------------------------------------------------------------------------+
  1409. |                                                                             |
  1410. | SYNOPSIS                                                                    |
  1411. | ~~~~~~~~                                                                    |
  1412. |   #include <stdio.h>                                                        |
  1413. |   #include <os2.h>                                                          |
  1414. |                                                                             |
  1415. |   int draw_box (char box_type, int left_column, int right_column,           |
  1416. |                 int top_row, int bottom_row);                               |
  1417. | FUNCTION                                                                    |
  1418. | ~~~~~~~~                                                                    |
  1419. |   Draws double-line bordered box bounded by left_column, right_column,      |
  1420. |   top_row and bottom_row.  If box_type is 'p', draws a plain box;           |
  1421. |   otherwise draws a box with a label section at the top.                    |
  1422. |                                                                             |
  1423. | RETURNS                                                                     |
  1424. | ~~~~~~~                                                                     |
  1425. |   Nothing.                                                                  |
  1426. |                                                                             |
  1427. |                                                                             |
  1428. |                                                                             |
  1429. | NOTES                                                                       |
  1430. | ~~~~~                                                                       |
  1431. |  Uses VioWrtNChar, a MSC extesntion which may not be portable accross       |
  1432. |   operating systems and compilers.                                          |
  1433. |                                                                             |
  1434. |                                                                             |
  1435. |                                                                             |
  1436. +----------------------------------------------------------------------------*/
  1437.  
  1438. void draw_box (box_type, left_column, right_column, top_row, bottom_row)  
  1439.  
  1440.   char          box_type;                       /* code for box design type  */
  1441.   USHORT        left_column;                           /* left column of box */
  1442.   USHORT        right_column;                         /* right column of box */
  1443.   USHORT        top_row;                                   /* top row of box */
  1444.   USHORT        bottom_row;                             /* bottom row of box */
  1445.   
  1446. {
  1447.  
  1448.   USHORT       count;                                             /* counter */
  1449.   HVIO             hvio = 0;                                     /* video handle */
  1450.   USHORT       cb = 1;                 /* number of times to write character */
  1451.  
  1452.   VioWrtNChar ("\xC9",cb,top_row,left_column,hvio);     /* upper left corner */
  1453.  
  1454.   for (count = (left_column + 1); count < right_column; count++) 
  1455.   {                                                           /* top border  */
  1456.     VioWrtNChar ("\xCD",cb,top_row,count,hvio); /* print horizontal dbl line */
  1457.   }
  1458.  
  1459.   VioWrtNChar ("\xBB",cb,top_row,right_column,hvio);   /* upper right corner */
  1460.  
  1461.   for (count = (top_row + 1); count < bottom_row; count++)
  1462.   {                                                     /* print left border */
  1463.     VioWrtNChar ("\xBA",cb,count,left_column,hvio);         /* left vertical */
  1464.   }
  1465.  
  1466.   for (count = (top_row + 1); count < bottom_row; count++)
  1467.   {                                                    /* print right border */
  1468.     VioWrtNChar ("\xBA",cb,count,right_column,hvio);       /* right vertical */
  1469.   }
  1470.  
  1471.   VioWrtNChar ("\xC8",cb,bottom_row,left_column,hvio);  /* lower left corner */
  1472.  
  1473.   for (count = (left_column + 1); count < right_column; count++)
  1474.   {                                                   /* print bottom border */
  1475.     VioWrtNChar ("\xCD",cb,bottom_row,count,hvio);          /* bottom border */
  1476.   }
  1477.  
  1478.   VioWrtNChar ("\xBC",cb,bottom_row,right_column,hvio);/* lower right corner */
  1479.  
  1480.   if ((box_type == 'p') || (box_type == 'P'))          /* if plain box, exit */
  1481.     return;  
  1482.  
  1483.   VioWrtNChar ("\xC7",cb,(top_row + 4),left_column,hvio);  /* left connector */
  1484.  
  1485.   for (count = (left_column + 1); count < right_column; count++)
  1486.   {                    /* print single horizonal line accross 5th row of box */
  1487.     VioWrtNChar ("\xC4",cb,(top_row + 4),count,hvio);     /* horizontal line */
  1488.   }
  1489.  
  1490.   VioWrtNChar ("\xB6",cb,(top_row + 4),right_column,hvio);/* right connector */
  1491. }
  1492.  
  1493. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ draw_box ^^^^*/
  1494.  
  1495. #pragma subtitle("editLdata()")
  1496. #pragma page()
  1497.  
  1498. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv editLdata vvvv*/
  1499.  
  1500. /*----------------------------------------------------------------------------+
  1501. |                                                                             |
  1502. | SYNOPSIS                                                                    |
  1503. | ~~~~~~~~                                                                    |
  1504. | #include <stdio.h>                                                          |
  1505. | #include <string.h>                                                         |
  1506. | void editLdata (char *data_string, int width)                               |
  1507. |                                                                             |
  1508. | FUNCTION                                                                    |
  1509. | ~~~~~~~~                                                                    |
  1510. |   Edits data at data_string pointer to all upper case and to specified      |
  1511. |   width, padding with trailing spaces if necessary. Left justifies.         |
  1512. |                                                                             |
  1513. | RETURNS                                                                     |
  1514. | ~~~~~~~                                                                     |
  1515. |   Nothing.                                                                  |
  1516. |                                                                             |
  1517. |                                                                             |
  1518. |                                                                             |
  1519. | NOTES                                                                       |
  1520. | ~~~~~                                                                       |
  1521. |                                                                             |
  1522. |   Uses ANSI standard functions only; should be portable.   Uses             |
  1523. |   string functions declared in string.h.                                    |
  1524. |                                                                             |
  1525. |                                                                             |
  1526. |                                                                             |
  1527. +----------------------------------------------------------------------------*/
  1528.  
  1529. void editLdata (data_string, width)    /* func to edit data to record format */
  1530.  
  1531.   char             *data_string;                 /* ptr to data to be edited */
  1532.   int               width;                               /* edit field width */
  1533.  
  1534. {
  1535.   int               char_limit;        /* max string length (non_null chars) */
  1536.   extern void       trim();      /* func trims leading & trailing whitespace */
  1537.  
  1538.   char_limit = width - 1;                     /* determine max string length */
  1539.  
  1540.         /* delete leading and trailing white space */
  1541.         
  1542.   trim (data_string);
  1543.   
  1544.         /* convert all characters to upper case */
  1545.  
  1546.   strupr (data_string);
  1547.   
  1548.         /* truncate to correct length */
  1549.  
  1550.   if (strlen (data_string) > (char_limit))             /* if data too long - */
  1551.     data_string [char_limit] = '\0';           /* - terminate at field width */
  1552.  
  1553.          /* pad with trailing blanks to correct length */
  1554.  
  1555.   while (strlen (data_string) < (char_limit)) /* while data not long enough  */
  1556.     strcat (data_string, " ");                            /* - append blanks */
  1557.   
  1558. }
  1559.  
  1560. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ editLdata ^^^^*/
  1561.  
  1562. #pragma subtitle("editRdata()")
  1563. #pragma page()
  1564.  
  1565. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv editRdata vvvv*/
  1566.  
  1567. /*----------------------------------------------------------------------------+
  1568. |                                                                             |
  1569. | SYNOPSIS                                                                    |
  1570. | ~~~~~~~~                                                                    |
  1571. | #include <stdio.h>                                                          |
  1572. | #include <string.h>                                                         |
  1573. | void editRdata (char *data_string, int width)                               |
  1574. |                                                                             |
  1575. | FUNCTION                                                                    |
  1576. | ~~~~~~~~                                                                    |
  1577. |   Edits data at data_string pointer to all upper case and to specified      |
  1578. |   width, padding with leading  spaces if necessary. Right justifies.        |
  1579. |                                                                             |
  1580. | RETURNS                                                                     |
  1581. | ~~~~~~~                                                                     |
  1582. |   Nothing.                                                                  |
  1583. |                                                                             |
  1584. |                                                                             |
  1585. |                                                                             |
  1586. | NOTES                                                                       |
  1587. | ~~~~~                                                                       |
  1588. |                                                                             |
  1589. |   Uses ANSI standard functions only; should be portable.   Uses             |
  1590. |   string functions declared in string.h.                                    |
  1591. |                                                                             |
  1592. |                                                                             |
  1593. |                                                                             |
  1594. +----------------------------------------------------------------------------*/
  1595.  
  1596. void editRdata (data_string, width)    /* func to edit data to record format */
  1597.  
  1598.   char             *data_string;                 /* ptr to data to be edited */
  1599.   int               width;                               /* edit field width */
  1600.  
  1601. {
  1602.   int               char_limit;        /* max string length (non_null chars) */
  1603.   char              temp[255];                                 /* difference */
  1604.   extern void       trim();      /* func trims leading & trailing whitespace */
  1605.  
  1606.   char_limit = width - 1;                     /* determine max string length */
  1607.  
  1608.         /* delete leading and trailing white space */
  1609.         
  1610.   trim (data_string);
  1611.  
  1612.         /* convert all characters to upper case */
  1613.  
  1614.   strupr (data_string);
  1615.   
  1616.         /* truncate to correct length */
  1617.  
  1618.   if (strlen (data_string) > (char_limit))             /* if data too long - */
  1619.     data_string [char_limit] = '\0';           /* - terminate at field width */
  1620.  
  1621.          /* pad with leading blanks to correct length */
  1622.  
  1623.       
  1624.   while (strlen (data_string) < (char_limit)) /* while data not long enough  */
  1625.   {
  1626.     strcpy (temp, data_string);                         /* copy data to temp */
  1627.     strcpy (data_string, " ");                /* replace data with one blank */
  1628.     strcat (data_string, temp);                  /* concatenate temp to data */
  1629.   }  
  1630. }
  1631.  
  1632. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ editRdata ^^^^*/
  1633.  
  1634. #pragma subtitle("file_convert()")
  1635. #pragma page()
  1636.  
  1637. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv file_convert vvvv*/
  1638.  
  1639. /*----------------------------------------------------------------------------+
  1640. |                                                                             |
  1641. | SYNOPSIS                                                                    |
  1642. | ~~~~~~~~                                                                    |
  1643. |   #include <stdio.h>                                                        |
  1644. |   void file_convert ( char *base_file_id, char *work_file_id)               |
  1645. |                                                                             |
  1646. | FUNCTION                                                                    |
  1647. | ~~~~~~~~                                                                    |
  1648. |   Converts a data base file created under version 4.x to the format         |
  1649. |   utilized in version 5.x.                                                  |
  1650. |                                                                             |
  1651. | RETURNS                                                                     |
  1652. | ~~~~~~~                                                                     |
  1653. |   Nothing.                                                                  |
  1654. |                                                                             |
  1655. |                                                                             |
  1656. | NOTES                                                                       |
  1657. | ~~~~~                                                                       |
  1658. |   Calls functions which utilize non-standard MSC extensions.                |
  1659. |   May not be portable accross compilers and operating systems.              |
  1660. |   This function is necessary because earlier versions were compiled         |
  1661. |   on a Computer Innovations compiler which does not align records on        |
  1662. |   word boundries and thus constructed a MOVIERECORD to fill one byte less   |
  1663. |   than the Microsoft compiler, which allocated an extra byte to align       |
  1664. |   the end of a record with a word boundry.  The definition of MOVIERECORD   |
  1665. |   has now been changed so both compilers use the same number of bytes.      |
  1666. |                                                                             |
  1667. +----------------------------------------------------------------------------*/
  1668.  
  1669.  
  1670. void file_convert ( base_file_id, work_file_id)
  1671.  
  1672.   char                 *base_file_id;        /* pointer to name of base file */
  1673.   char                 *work_file_id;        /* pointer to name of work file */
  1674.   
  1675. {
  1676.  
  1677.   FILE                 *basef_ptr;                       /* base file stream */
  1678.   char                 *buf1;
  1679.   char                 *buf2;
  1680.   USHORT                cbString;                       /* string byte count */
  1681.   char                 *char_buff;                       /* character buffer */
  1682.   extern void           clear_screen();  /* func clears screen & sets colors */
  1683.   int                   count;              /* counter for records processed */
  1684.   extern void           cur_size();                 /* func sets cursor size */
  1685.   extern void           editLdata();       /* func edits data left justified */
  1686.   extern void           editRdata();      /* func edits data right justified */
  1687.   extern void           file_con_get_id();     /* func gets old base file id */
  1688.   extern void           file_con_menu();             /* func to display menu */
  1689.   extern int            has_color();        /* func checks for color display */
  1690.   int                   new_size;                 /* new size of data record */
  1691.   HVIO                  hvio = 0;                            /* video handle */
  1692.   char                  old_base_file_id[255];           /* old data file id */
  1693.   FILE                 *old_basef_ptr;                   /* base file stream */
  1694.   int                   old_size;                 /* old size of data record */
  1695.   struct MOVIERECORD   *rec_buff;                 /* buffer to hold 1 record */
  1696.   char                  response [INPUTLENGTH];             /* user response */
  1697.   extern void           set_cursor();           /* func sets cursor position */
  1698.   FILE                 *workf_ptr;                       /* work file stream */
  1699.  
  1700.   char_buff = (char *) calloc (1, 0x100);
  1701.   file_con_menu();                              /* call func to display menu */
  1702.   sprintf (char_buff,"Do you wish to continue with file conversion (Y/N -> ");
  1703.   cbString = (USHORT)strlen(char_buff);             /* get string byte count */
  1704.   VioWrtCharStr (char_buff,cbString,21,5,hvio);         /* write user prompt */
  1705.   VioSetCurPos (21,(5 + cbString),hvio);                  /* position cursor */
  1706.   gets (response);                                      /* get user response */
  1707.   trim (response);                          /* trim whitespace from response */
  1708.   if ((response[0] == 'N') || (response[0] == 'n'))           /* if N or n - */
  1709.     return;                                                         /* abort */
  1710.              /* find old base file */
  1711.  
  1712.   file_con_get_id(old_base_file_id);    /* call func to get old base file id */
  1713.   if (old_base_file_id[0] == '\0')                      /* if no id returned */
  1714.     return;                                                         /* abort */
  1715.     
  1716.           /* set up screen and open files */
  1717.  
  1718.   count = 0;
  1719.   new_size = sizeof(struct MOVIERECORD);
  1720.   old_size = new_size - 1;
  1721.   clear_screen (LRED, BLACK);           /* clear screen & set display colors */
  1722.   sprintf (char_buff, "CONVERTING - READING OLD BASE FILE..");/* advise user */
  1723.   cbString = (USHORT)strlen(char_buff);             /* get string byte count */
  1724.   VioWrtCharStr (char_buff,cbString,11,11,hvio);            /* write message */
  1725.   VioSetCurPos (11, (11 + cbString), hvio);           /* set cursor position */
  1726.   rec_buff = (struct MOVIERECORD *)calloc (1, sizeof (struct MOVIERECORD));
  1727.   rec_buff = (struct MOVIERECORD *)memset                    /* clear buffer */
  1728.      ((char *)rec_buff, '\0', sizeof(struct MOVIERECORD));
  1729.   buf1 = calloc (1, BIGBUFF);
  1730.   buf2 = calloc (2, BIGBUFF);
  1731.   workf_ptr = fopen (work_file_id, "wb");                  /* open work file */
  1732.   setvbuf (workf_ptr, buf1, _IOFBF, BIGBUFF); /* use big buffer for file i/o */
  1733.   if (workf_ptr == NULL)                /* if file not successfully opened - */
  1734.   {
  1735.     printf ("\n Error in opening work file.\n");              /* - warn user */
  1736.     pause();                                              /* - wait for user */
  1737.     fcloseall();                                        /* - close all files */
  1738.     return;
  1739.   }
  1740.   old_basef_ptr = fopen (old_base_file_id, "rb");          /* open base file */
  1741.   setvbuf (old_basef_ptr, buf2, _IOFBF, BIGBUFF);  /* use big buffer for i/o */
  1742.   if (old_basef_ptr == NULL)            /* if file not successfully opened - */
  1743.   {
  1744.     printf ("\n Error in opening OLD base file.\n");          /* - warn user */
  1745.     pause();                                              /* - wait for user */
  1746.     fcloseall();                                        /* - close all files */
  1747.     return;
  1748.   }
  1749.  
  1750.              /* process update  from base file and transactions */
  1751.              /*  to work file */
  1752.  
  1753.   VioSetCurPos (23,0,hvio);                           /* set cursor position */
  1754.  
  1755.   while (!(feof (old_basef_ptr)))         /* while not at end of work file - */
  1756.   {
  1757.     if ((fread ((char *)rec_buff, old_size,
  1758.        1, old_basef_ptr)) != 1)                             /* read a record */
  1759.     {                                                     /* if read error - */
  1760.       if (feof(old_basef_ptr))                        /* - if EOF break loop */
  1761.         break;                          /*   and continue (normal condition) */
  1762.       else 
  1763.       {                                           /* - if other read error - */
  1764.         printf ("\nError in reading old base file.\n");         /* warn user */
  1765.         pause();                                            /* wait for user */
  1766.         fcloseall();                                      /* close all files */
  1767.         return;
  1768.       }
  1769.     }
  1770.     editLdata (rec_buff->title, TITLELENGTH);       /* edit fields to        */
  1771.     editLdata (rec_buff->year, YEARLENGTH);         /*  current standards    */
  1772.     editLdata (rec_buff->star1, NAMELENGTH);
  1773.     editLdata (rec_buff->star2, NAMELENGTH);
  1774.     editLdata (rec_buff->star3, NAMELENGTH);
  1775.     editLdata (rec_buff->director, NAMELENGTH);
  1776.     editRdata (rec_buff->loc1, LOCLENGTH);
  1777.     editRdata (rec_buff->loc2, LOCLENGTH);
  1778.     if ((fwrite ((char *)rec_buff, new_size,
  1779.        1, workf_ptr)) != 1)                     /* write record to base file */
  1780.     {                                                    /* if write error - */
  1781.       printf ("\nError in writing work file.\n");               /* warn user */
  1782.       pause();                                              /* wait for user */
  1783.       fcloseall();                                        /* close all files */
  1784.       return;
  1785.     }
  1786.    else       /* if record successfully transferred from work to base file - */
  1787.     {
  1788.       sprintf (char_buff, "%4d ", count++);         /* write count to buffer */
  1789.       cbString = (USHORT)strlen(char_buff);                /* get byte count */
  1790.       VioWrtCharStr (char_buff,cbString,11,50,hvio);      /* write to screen */
  1791.     }            
  1792.   }
  1793.   if (fclose (workf_ptr))                                  /* close workfile */
  1794.     {                                                    /* if close error - */
  1795.       printf ("\nError in closing work file.\n");               /* warn user */
  1796.       pause();                                              /* wait for user */
  1797.       fcloseall();                                        /* close all files */
  1798.       return;
  1799.     }
  1800.   if (fclose (old_basef_ptr))                             /* close base file */
  1801.     {                                                    /* if close error - */
  1802.       printf ("\nError in closing old base file.\n");           /* warn user */
  1803.       pause();                                              /* wait for user */
  1804.       fcloseall();                                        /* close all files */
  1805.       return;
  1806.     }
  1807.  
  1808.   clear_screen (LGREEN, BLACK);         /* clear screen & set display colors */
  1809.   sprintf (char_buff, "CONVERTING - WRITING NEW BASE FILE..");/* advise user */
  1810.   cbString = (USHORT)strlen(char_buff);             /* get string byte count */
  1811.   VioWrtCharStr (char_buff,cbString,11,11,hvio);            /* write message */
  1812.   VioSetCurPos (23, 0, hvio);                         /* set cursor position */
  1813.   workf_ptr = fopen (work_file_id, "rb");                  /* open work file */
  1814.   setvbuf (workf_ptr, buf1, _IOFBF, BIGBUFF); /* use big buffer for file i/o */
  1815.   if (workf_ptr == NULL)                /* if file not successfully opened - */
  1816.   {
  1817.     printf ("\n Error in opening work file.\n");              /* - warn user */
  1818.     pause();                                              /* - wait for user */
  1819.     fcloseall();                                        /* - close all files */
  1820.     return;
  1821.   }
  1822.   basef_ptr = fopen (base_file_id, "wb");                  /* open base file */
  1823.   setvbuf (basef_ptr, buf2, _IOFBF, BIGBUFF); /* use big buffer for file i/o */
  1824.   if (basef_ptr == NULL)                /* if file not successfully opened - */
  1825.   {
  1826.     printf ("\n Error in opening base file.\n");              /* - warn user */
  1827.     pause();                                              /* - wait for user */
  1828.     fcloseall();                                        /* - close all files */
  1829.     return;
  1830.   }
  1831.  
  1832.  
  1833.   while (!(feof (workf_ptr)))             /* while not at end of work file - */
  1834.   {
  1835.     if ((fread ((char *)rec_buff, new_size,   
  1836.        1, workf_ptr)) != 1)                                 /* read a record */
  1837.     {                                                     /* if read error - */
  1838.       if (feof(workf_ptr))                            /* - if EOF break loop */
  1839.         break;                          /*   and continue (normal condition) */
  1840.       else 
  1841.       {                                           /* - if other read error - */
  1842.         printf ("\nError in reading work file.\n");             /* warn user */
  1843.         pause();                                            /* wait for user */
  1844.         fcloseall();                                      /* close all files */
  1845.       }
  1846.     }
  1847.     if ((fwrite ((char *)rec_buff, new_size,
  1848.        1, basef_ptr)) != 1)                     /* write record to base file */
  1849.     {                                                    /* if write error - */
  1850.       printf ("\nError in writing base file.\n");               /* warn user */
  1851.       pause();                                              /* wait for user */
  1852.       fcloseall();                                        /* close all files */
  1853.     }
  1854.    else       /* if record successfully transferred from work to base file - */
  1855.     {
  1856.       sprintf (char_buff, "%4d ", count--);         /* write count to buffer */
  1857.       cbString = (USHORT)strlen(char_buff);                /* get byte count */
  1858.       VioWrtCharStr (char_buff,cbString,11,50,hvio);      /* write to screen */
  1859.     }            
  1860.   }
  1861.   free ((char *)(rec_buff));              /* free memory allocated to buffer */
  1862.   free (buf1);
  1863.   free (buf2);
  1864.   free (char_buff);
  1865.   if (fclose (workf_ptr))                                  /* close workfile */
  1866.     {                                                    /* if close error - */
  1867.       printf ("\nError in closing work file.\n");               /* warn user */
  1868.       pause();                                              /* wait for user */
  1869.       fcloseall();                                        /* close all files */
  1870.       return;
  1871.     }
  1872.   if (fclose (basef_ptr))                                 /* close base file */
  1873.     {                                                    /* if close error - */
  1874.       printf ("\nError in closing base file.\n");               /* warn user */
  1875.       pause();                                              /* wait for user */
  1876.       fcloseall();                                        /* close all files */
  1877.       return;
  1878.     }
  1879. }
  1880.  
  1881. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ file_convert ^^^^*/
  1882.  
  1883. #pragma subtitle("file_con_menu()")
  1884. #pragma page()
  1885.  
  1886. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv file_con_menu vvvv*/
  1887.  
  1888. /*----------------------------------------------------------------------------+
  1889. |                                                                             |
  1890. | SYNOPSIS                                                                    |
  1891. | ~~~~~~~~                                                                    |
  1892. |   #include <stdio.h>                                                        |
  1893. |   void file_con_menu()                                                      |
  1894. |                                                                             |
  1895. | FUNCTION                                                                    |
  1896. | ~~~~~~~~                                                                    |
  1897. |   Displays a menu with an explanation of the file conversion function       |
  1898. |   and user choices.                                                         |
  1899. |                                                                             |
  1900. |                                                                             |
  1901. | RETURNS                                                                     |
  1902. | ~~~~~~~                                                                     |
  1903. |                                                                             |
  1904. |   Nothing.                                                                  |
  1905. |                                                                             |
  1906. |                                                                             |
  1907. | NOTES                                                                       |
  1908. | ~~~~~                                                                       |
  1909. |   Calls functions which use nonstandard C extensions and may not be         |
  1910. |   portable accross operating systems and compilers.                         |
  1911. |                                                                             |
  1912. |                                                                             |
  1913. |                                                                             |
  1914. |                                                                             |
  1915. +----------------------------------------------------------------------------*/
  1916.  
  1917. void file_con_menu()
  1918.  
  1919. {
  1920.   USHORT                cbString;                       /* string byte count */
  1921.   char                 *char_buff;                          /* string buffer */
  1922.   extern void           clear_screen();  /* func clears screen & sets colors */
  1923.   HVIO                  hvio = 0;                            /* video handle */
  1924.   extern void           draw_box();             /* func draws box on display */
  1925.   extern void           set_cursor();           /* func sets cursor position */
  1926.   extern void           window();               /* func opens display window */
  1927.  
  1928.   char_buff = (char *) calloc (1, 0x100);
  1929.   clear_screen (LWHITE, BLACK);                 /* clear screen & set colors */
  1930.   window (10,70,3,18,BLACK,RED);                              /* open window */
  1931.   draw_box ('l',11,69,3,18);                           /* draw box in window */
  1932.   set_cursor (5,33,0);                                    /* position cursor */
  1933.   sprintf (char_buff, "FILE CONVERSION");                   /* write to buff */
  1934.   cbString = (USHORT)strlen(char_buff);                    /* get byte count */
  1935.   VioWrtCharStr(char_buff,cbString,5,33,hvio);            /* write to screen */
  1936.   sprintf (char_buff, "This function converts a file created under");
  1937.   cbString = (USHORT)strlen(char_buff);                    /* get byte count */
  1938.   VioWrtCharStr(char_buff,cbString,8,15,hvio);            /* write to screen */
  1939.   sprintf (char_buff, "Version 4.x series versions of this program to");
  1940.   cbString = (USHORT)strlen(char_buff);                    /* get byte count */
  1941.   VioWrtCharStr(char_buff,cbString,9,15,hvio);            /* write to screen */
  1942.   sprintf (char_buff, "a new data file in a format compatible with the");
  1943.   cbString = (USHORT)strlen(char_buff);                    /* get byte count */
  1944.   VioWrtCharStr(char_buff,cbString,10,15,hvio);           /* write to screen */
  1945.   sprintf (char_buff, "Versions 5.x-6.x Series.  You will be asked to ");
  1946.   cbString = (USHORT)strlen(char_buff);                    /* get byte count */
  1947.   VioWrtCharStr(char_buff,cbString,11,15,hvio);           /* write to screen */
  1948.   sprintf (char_buff, "enter the path of the old base file (BASEFILE.DAT).");
  1949.   cbString = (USHORT)strlen(char_buff);                    /* get byte count */
  1950.   VioWrtCharStr(char_buff,cbString,12,15,hvio);           /* write to screen */
  1951.   sprintf (char_buff, "The new file (BASEFIL5.DAT) will be created on ");
  1952.   cbString = (USHORT)strlen(char_buff);                    /* get byte count */
  1953.   VioWrtCharStr(char_buff,cbString,13,15,hvio);           /* write to screen */
  1954.   sprintf (char_buff, "the path you previously identified for the     ");
  1955.   cbString = (USHORT)strlen(char_buff);                    /* get byte count */
  1956.   VioWrtCharStr(char_buff,cbString,14,15,hvio);           /* write to screen */
  1957.   sprintf (char_buff, "current base file.  This procedure is unnecessary");
  1958.   cbString = (USHORT)strlen(char_buff);                    /* get byte count */
  1959.   VioWrtCharStr(char_buff,cbString,15,15,hvio);           /* write to screen */
  1960.   sprintf (char_buff, "if you do not have a file created under Ver. 4.x.");
  1961.   cbString = (USHORT)strlen(char_buff);                    /* get byte count */
  1962.   VioWrtCharStr(char_buff,cbString,16,15,hvio);           /* write to screen */
  1963.  
  1964.   free (char_buff);
  1965.  
  1966. }
  1967.  
  1968. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ file_con_menu ^^^^*/
  1969.  
  1970. #pragma subtitle("file_con_get_id()")
  1971. #pragma page()
  1972.  
  1973. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv file_con_get_id vvvv*/
  1974.  
  1975. /*----------------------------------------------------------------------------+
  1976. |                                                                             |
  1977. | SYNOPSIS                                                                    |
  1978. | ~~~~~~~~                                                                    |
  1979. |   #include <stdio.h>                                                        |
  1980. |   #include <string.h>                                                       |
  1981. |   #include <direct.h>                                                       |
  1982. |   char *file_con_get_id();                                                  |
  1983. |                                                                             |
  1984. |  FUNCTION                                                                   |
  1985. |  ~~~~~~~~                                                                   |
  1986. |   Gets complete file id for old base file by asking user for path           |
  1987. |   and checking for presence of old base file.                               |
  1988. |                                                                             |
  1989. | RETURNS                                                                     |
  1990. | ~~~~~~~                                                                     |
  1991. |   Pointer to file_id string if successfull; NULL if not successful.         |
  1992. |                                                                             |
  1993. | NOTES                                                                       |
  1994. | ~~~~~                                                                       |
  1995. |   Uses getcwd(), an MSC extension wihc may not be portable.                 |
  1996. |                                                                             |
  1997. +----------------------------------------------------------------------------*/
  1998.  
  1999.  
  2000. void file_con_get_id(old_base_file_id)      /* get file id for old base file */
  2001.  
  2002.   char         *old_base_file_id;                 /* complete file id string */
  2003.  
  2004.  
  2005. {
  2006.  
  2007.   USHORT        cbString;                               /* string byte count */
  2008.   char         *char_buff;                                  /* string buffer */
  2009.   extern void   clear_screen();          /* func clears screen & sets colors */
  2010.   extern void   draw_box();                     /* func draws box on display */
  2011.   HVIO          hvio = 0;                                    /* video handle */
  2012.   char          old_base_path [INPUTLENGTH];        /* path to old_base file */
  2013.   FILE         *old_basef_ptr;                   /* pointer to old_base file */
  2014.   char         *cdir_ptr;                    /* pointer to current directory */
  2015.   extern char   pause();                             /* func pauses for user */
  2016.   char          response [INPUTLENGTH];                     /* user response */
  2017.   extern void   set_border();              /* func sets display border color */
  2018.   extern void   set_cursor();                   /* func sets cursor position */
  2019.   extern void   trim();                             /* func trims whitespace */
  2020.   extern void   window();                       /* func opens display window */
  2021.  
  2022.  
  2023.   char_buff = (char *) calloc (1, 0x100);
  2024.   clear_screen (LWHITE,BLACK);          /* clear screen & set display colors */
  2025.   VioSetCurPos(23,1,hvio);          
  2026.   cdir_ptr = getcwd(NULL,80);
  2027.  
  2028.   strcpy (old_base_path, cdir_ptr);    /* copy current path to old base path */
  2029.   free ((char *)cdir_ptr);                        /* - free pointer          */
  2030.   trim (old_base_path);                              /* trim whitespace (\n) */
  2031.                                                  /* strip trailing backslash */
  2032.   while (old_base_path[strlen(old_base_path) -1] == '\\')
  2033.     old_base_path [strlen(old_base_path) -1] = '\0';
  2034.  
  2035.     /* advise user of current path */
  2036.  
  2037.   sprintf (char_buff,"Current path is %s", old_base_path);
  2038.   cbString = (USHORT)strlen(char_buff);
  2039.   VioWrtCharStr(char_buff,cbString,5,5,hvio);
  2040.  
  2041.         /* find out if user wants to change paths */
  2042.         
  2043.   sprintf                                                      /* prompt user */
  2044.    (char_buff,"Is the OLD base file on this path? (Y/N) -> ");
  2045.   cbString = (USHORT)strlen(char_buff);
  2046.   VioWrtCharStr(char_buff,cbString,7,5,hvio);
  2047.   VioSetCurPos(7,(5 + strlen(char_buff)),hvio);
  2048.   gets (response);                                      /* get user response */
  2049.   trim (response);                          /* trim whitespace from response */
  2050.   if ((response[0] == 'N') || (response[0] == 'n'))           /* if N or n - */
  2051.   {
  2052.     sprintf
  2053.       (char_buff, "Enter correct path for OLD data base file ->");
  2054.     cbString = (USHORT)strlen(char_buff);
  2055.     VioWrtCharStr(char_buff,cbString,9,5,hvio);
  2056.     VioSetCurPos(9,(5 + strlen(char_buff)),hvio);
  2057.     gets (old_base_path);                       /* get base path from console*/
  2058.     trim (old_base_path);                                 /* trim whitespace */
  2059.                                                  /* strip trailing backslash */
  2060.     while (old_base_path[strlen(old_base_path) -1] == '\\')
  2061.       old_base_path [strlen(old_base_path) -1] = '\0';
  2062.   }
  2063.  
  2064.  
  2065.         /* attempt to open old_base file */
  2066.         /* warn user if unsuccessful */
  2067.         
  2068.   strcpy (old_base_file_id, old_base_path);                     /* copy path */
  2069.   strcat (old_base_file_id, "\\BASEFILE.DAT");             /* append file id */
  2070.   old_basef_ptr = fopen (old_base_file_id, "r");            /* open for read */
  2071.   if (old_basef_ptr == NULL)                                /* if open error */
  2072.   {                                                         /* - advise user */
  2073.     sprintf (char_buff,"%s not found; cannot continue conversion.",
  2074.                  old_base_file_id);
  2075.     cbString = (USHORT)strlen(char_buff);
  2076.     VioWrtCharStr(char_buff,cbString,11,5,hvio);
  2077.     VioSetCurPos(23,1,hvio);
  2078.     pause();                                                /* wait for user */
  2079.     fcloseall();                                          /* close all files */
  2080.     old_base_file_id[0] = '\0';                  /* blank out file id string */
  2081.     return;                                                  /* return blank */
  2082.   }
  2083.   fclose (old_basef_ptr);                       /* if successful, close file */
  2084.   free (char_buff);
  2085.   return;                                       /* and return file id string */
  2086. }
  2087.  
  2088. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ file_con_get_id ^^^^*/
  2089.  
  2090. #pragma subtitle("get_change()")
  2091. #pragma page()
  2092.  
  2093.  
  2094. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv get_change vvvv*/
  2095.  
  2096. /*----------------------------------------------------------------------------+
  2097. |                                                                             |
  2098. | SYNOPSIS                                                                    |
  2099. | ~~~~~~~~                                                                    |
  2100. |   #include <stdio.h>                                                        |
  2101. |   #include <string.h>                                                       |
  2102. |   #include <dos.h>                                                          |
  2103. |   int get_change (struct MOVIETRANS *trans1_ptr, *trans2_ptr,               |
  2104. |                   char *base_file_id)                                       |
  2105. | FUNCTION                                                                    |
  2106. | ~~~~~~~~                                                                    |
  2107. |   Change an existing record in the base file.  Prompts user to identify     |
  2108. |   record to be changed by title and year; searches for record; if found,    |
  2109. |   stores it at trans1_ptr as an add transaction and copies to trans2_ptr    |
  2110. |   as a delete transaction, then prompts user for changes to the add trans.  |
  2111. |                                                                             |
  2112. | RETURNS                                                                     |
  2113. | ~~~~~~~                                                                     |
  2114. |   TRUE (defined in videocat) if record to be changed is successfully        |
  2115. |   located; otherwise returns FALSE.                                         |
  2116. |                                                                             |
  2117. |                                                                             |
  2118. | NOTES                                                                       |
  2119. | ~~~~~                                                                       |
  2120. |   Calls program functions which use MSC extensions; may not be portable     |
  2121. |   accross compilers and operating systems.                                  |
  2122. |                                                                             |
  2123. |                                                                             |
  2124. +----------------------------------------------------------------------------*/
  2125.  
  2126. get_change (trans1_ptr, trans2_ptr, base_file_id)  /* get record & change it */
  2127.  
  2128.   struct MOVIETRANS    *trans1_ptr, *trans2_ptr;  /* pointers to trans buffs */
  2129.   char                 *base_file_id;               /* file id for base file */
  2130.  
  2131. {
  2132.   FILE                 *basef_ptr;                       /* ptr to base file */
  2133.   char                 *iobuf;                                 /* i/o buffer */
  2134.   USHORT                cbString;                       /* string byte count */
  2135.   char                 *char_buff;                      /* buffer for string */
  2136.   extern void           clear_screen(); /* func to clear screen & set colors */
  2137.   char                  command = '\0';          /* change type command code */
  2138.   extern void           display();       /* func displays contents of record */
  2139.   extern void           draw_box();                        /* func draws box */
  2140.   int                   found = FALSE;      /* boolean flag for record found */
  2141.   extern void           get_form();              /* func gets form from user */
  2142.   extern void           get_loc();           /* func gets location from user */
  2143.   extern void           get_mpaa_code();       /* func gets rating from user */
  2144.   extern void           get_name();              /* func gets name from user */
  2145.   extern void           get_rating();          /* func gets rating from user */
  2146.   extern void           get_subject();        /* func gets subject from user */
  2147.   extern void           get_title();            /* func gets title from user */
  2148.   extern void           get_year();              /* func gets year from user */
  2149.   HVIO                  hvio = 0;                            /* video handle */
  2150.   char                  input_command [INPUTLENGTH];    /* user input buffer */
  2151.   extern char           pause();                     /* func pauses for user */
  2152.   struct MOVIERECORD   *rec1_ptr;                  /* pointer to data record */
  2153.   struct MOVIERECORD   *rec2_ptr;                  /* pointer to data record */
  2154.   extern void           set_border();       /* func sets screen border color */
  2155.   extern void           set_cursor();           /* func sets cursor position */
  2156.   int                   tcomp_result = 0;      /* result of title comparison */
  2157.   extern void           trim();        /* func trims lead & trail whitespace */
  2158.   extern int            verify();            /* func gets data verification  */
  2159.   int                   ycomp_result = 0;       /* result of year comparison */
  2160.  
  2161.   rec1_ptr = &trans1_ptr->moviedata;      /* set record pointers to point to */
  2162.   rec2_ptr = &trans2_ptr->moviedata;    /* records in transaction structures */
  2163.   iobuf = calloc (1, BIGBUFF);              /* allocate memory to i/o buffer */
  2164.   char_buff = (char *) calloc (1, 0x100);
  2165.   
  2166.             /* set up screen display */
  2167.               
  2168.   clear_screen (LWHITE,BLACK);                  /* clear screen & set colors */
  2169.   window (0,79,0,21,LWHITE,BLUE);
  2170.   window (22,61,3,19,BLACK,BLACK);
  2171.   window (20,59,2,18,BLACK,WHITE);
  2172.   set_border (BLUE);                              /* set screen border color */
  2173.   VioSetCurPos (22,0,hvio);                               /* position cursor */
  2174.  
  2175.             /* display message and wait for user */
  2176.             
  2177.  
  2178.   clear_screen (LWHITE,BLACK);                  /* clear screen & set colors */
  2179.   window (0,79,0,21,LWHITE,BLUE);
  2180.   window (6,78,9,14,BLACK,BLACK);
  2181.   window (4,76,8,13,BLACK,WHITE);
  2182.   sprintf (char_buff, "Prepare to enter data to change a video record.");
  2183.   cbString = (USHORT)strlen(char_buff);
  2184.   VioWrtCharStr (char_buff,cbString,10,9,hvio);
  2185.   sprintf (char_buff, "Title and year must match an existing record...");
  2186.   cbString = (USHORT)strlen(char_buff);
  2187.   VioWrtCharStr (char_buff,cbString,11,9,hvio);
  2188.   set_border (BLUE);                              /* set screen border color */
  2189.   VioSetCurPos (22,0,hvio);                               /* position cursor */
  2190.   pause();
  2191.  
  2192.  
  2193.            /* identify record to be changed */
  2194.  
  2195.   get_title (rec1_ptr->title);                        /* get title from user */
  2196.   get_year (rec1_ptr->year);                           /* get year from user */
  2197.   basef_ptr = fopen (base_file_id, "rb");                  /* open base file */
  2198.   setvbuf (basef_ptr, iobuf, _IOFBF, BIGBUFF);         /* set big i/o buffer */
  2199.   clear_screen (LWHITE,BLACK);                  /* clear screen & set colors */
  2200.   window (0,79,0,21,LWHITE,BLUE);
  2201.   window (6,78,9,14,BLACK,BLACK);
  2202.   window (4,76,8,13,BLACK,WHITE);
  2203.   sprintf (char_buff, "Searching for record to be changed.............");
  2204.   cbString = (USHORT)strlen(char_buff);
  2205.   VioWrtCharStr (char_buff,cbString,10,9,hvio);
  2206.   set_border (BLUE);                              /* set screen border color */
  2207.   VioSetCurPos (22,0,hvio);                               /* position cursor */
  2208.  
  2209.        /* search base file for record with matching title and year */
  2210.        
  2211.   if (basef_ptr == NULL)                                  /* if open error - */
  2212.   {
  2213.     printf (" Error in attempting to open base file.\n");       /* warn user */
  2214.     pause();
  2215.     return FALSE;                                          /* & return error */
  2216.   }
  2217.   while ((!(feof (basef_ptr))) && (!(found))) /* while not EOF and not found */
  2218.   {
  2219.     if ((fread ((char *)&trans2_ptr->moviedata, sizeof(struct MOVIERECORD),
  2220.        1, basef_ptr)) != 1)                                 /* read a record */
  2221.     {                                                     /* if read error - */
  2222.       if (feof(basef_ptr))                            /* - if EOF break loop */
  2223.         break;                          /*   and continue (normal condition) */
  2224.       else 
  2225.       {                                           /* - if other read error - */
  2226.         printf (" Error in reading base file.\n");              /* warn user */
  2227.         pause();                                            /* wait for user */
  2228.         break;                      /* break off search (abnormal condition) */
  2229.       }
  2230.     }
  2231.     tcomp_result = strcmp (rec1_ptr->title,                /* compare search */
  2232.         rec2_ptr->title);                          /* title and record title */
  2233.     if (tcomp_result < 0)         /* if record is past targed in alpha order */
  2234.       break;                        /* break, no need to search rest of file */
  2235.     ycomp_result = strcmp (rec1_ptr->year,                  /*compare search */
  2236.         rec2_ptr->year);                             /* year and record year */
  2237.     if ((tcomp_result == 0) && (ycomp_result == 0))    /* if both title and  */
  2238.       {                                            /* year are exact matches */
  2239.         found = TRUE;                          /* then target has been found */
  2240.         break;                      /* break, no need to search rest of file */
  2241.       }
  2242.   }
  2243.   fclose (basef_ptr);                                     /* close base file */
  2244.   free (iobuf);                       /* free memory allocated to i/o buffer */
  2245.     
  2246.      /* process change of matching record, if found */
  2247.  
  2248.   if (!(found))                              /* if matching record not found */
  2249.   {
  2250.     VioSetCurPos(22,0,hvio);
  2251.     printf (" Record not found.\n");                            /* warn user */
  2252.     pause();
  2253.     return FALSE;                                     /* return error result */                                                   
  2254.   }  
  2255.   memcpy ((char *)&trans1_ptr->moviedata, (char *)&trans2_ptr->moviedata, 
  2256.     sizeof (struct MOVIERECORD));       /* copy record data to target buffer */
  2257.   trans2_ptr->transaction = 'D';          /* code buffer 2 as a delete trans */
  2258.   trans1_ptr->transaction = 'A';          /* code buffer 2 becomes add trans */
  2259.  
  2260.   while (command != 'Q')        /* loop while user has not entered Quit code */
  2261.   {
  2262.  
  2263.     clear_screen (LWHITE,BLACK);                /* clear screen & set colors */
  2264.     window (0,79,0,21,WHITE,BLUE);
  2265.     window (0,79,0,0,LWHITE,BLUE);
  2266.     window (6,78,2,5,BLACK,BLACK);
  2267.     window (4,76,1,4,BLACK,WHITE);
  2268.     set_border (BLUE);                            /* set screen border color */
  2269.     sprintf (char_buff,"Current content of replacement record:");
  2270.     cbString = (USHORT)strlen(char_buff);                  /* get byte count */
  2271.     VioWrtCharStr(char_buff,cbString,0,3,hvio);           /* write to screen */
  2272.     disp_rec (1,rec1_ptr);           /* display current content of add trans */
  2273.     VioSetCurPos (23,0,hvio);                             /* position cursor */
  2274.  
  2275.    
  2276.  
  2277.     draw_box ('L',2,77,6,20);
  2278.  
  2279.  
  2280.     sprintf (char_buff,"CHANGE MENU");                /* display change menu */
  2281.     cbString = (USHORT)strlen(char_buff);                  /* get byte count */
  2282.     VioWrtCharStr(char_buff,cbString,8,34,hvio);          /* write to screen */
  2283.  
  2284.     sprintf (char_buff, "T = change Title");
  2285.     cbString = (USHORT)strlen(char_buff);                  /* get byte count */
  2286.     VioWrtCharStr(char_buff,cbString,12,6,hvio);          /* write to screen */
  2287.  
  2288.     sprintf (char_buff, "Y = change Year");
  2289.     cbString = (USHORT)strlen(char_buff);                  /* get byte count */
  2290.     VioWrtCharStr(char_buff,cbString,13,6,hvio);          /* write to screen */
  2291.  
  2292.     sprintf (char_buff, "S = change Subject");
  2293.     cbString = (USHORT)strlen(char_buff);                  /* get byte count */
  2294.     VioWrtCharStr(char_buff,cbString,14,6,hvio);          /* write to screen */
  2295.  
  2296.     sprintf (char_buff, "F = change Form");
  2297.     cbString = (USHORT)strlen(char_buff);                  /* get byte count */
  2298.     VioWrtCharStr(char_buff,cbString,15,6,hvio);          /* write to screen */
  2299.  
  2300.     sprintf (char_buff, "R = change Rating");
  2301.     cbString = (USHORT)strlen(char_buff);                  /* get byte count */
  2302.     VioWrtCharStr(char_buff,cbString,16,6,hvio);          /* write to screen */
  2303.  
  2304.     sprintf (char_buff, "M = change MPAA code");
  2305.     cbString = (USHORT)strlen(char_buff);                  /* get byte count */
  2306.     VioWrtCharStr(char_buff,cbString,17,6,hvio);          /* write to screen */
  2307.  
  2308.     sprintf (char_buff, "1 = change Star 1 name");
  2309.     cbString = (USHORT)strlen(char_buff);                  /* get byte count */
  2310.     VioWrtCharStr(char_buff,cbString,12,40,hvio);         /* write to screen */
  2311.  
  2312.     sprintf (char_buff, "2 = change Star 2 name");
  2313.     cbString = (USHORT)strlen(char_buff);                  /* get byte count */
  2314.     VioWrtCharStr(char_buff,cbString,13,40,hvio);         /* write to screen */
  2315.  
  2316.     sprintf (char_buff, "3 = change Star 3 name");
  2317.     cbString = (USHORT)strlen(char_buff);                  /* get byte count */
  2318.     VioWrtCharStr(char_buff,cbString,14,40,hvio);         /* write to screen */
  2319.  
  2320.     sprintf (char_buff, "D = change Director name");
  2321.     cbString = (USHORT)strlen(char_buff);                  /* get byte count */
  2322.     VioWrtCharStr(char_buff,cbString,15,40,hvio);         /* write to screen */
  2323.  
  2324.     sprintf (char_buff, "C = change Cassette number");
  2325.     cbString = (USHORT)strlen(char_buff);                  /* get byte count */
  2326.     VioWrtCharStr(char_buff,cbString,16,40,hvio);         /* write to screen */
  2327.  
  2328.     sprintf (char_buff, "I = change Index number");
  2329.     cbString = (USHORT)strlen(char_buff);                  /* get byte count */
  2330.     VioWrtCharStr(char_buff,cbString,17,40,hvio);         /* write to screen */
  2331.  
  2332.     sprintf (char_buff, "Q = Quit - changes complete");
  2333.     cbString = (USHORT)strlen(char_buff);                  /* get byte count */
  2334.     VioWrtCharStr(char_buff,cbString,18,22,hvio);         /* write to screen */
  2335.  
  2336.     sprintf (char_buff, " Enter letter for desired function -> ");
  2337.     cbString = (USHORT)strlen(char_buff);                  /* get byte count */
  2338.     VioWrtCharStr(char_buff,cbString,23,0,hvio);          /* write to screen */
  2339.     VioSetCurPos (23,cbString,hvio); 
  2340.  
  2341.     gets (input_command);                                  /* get user input */
  2342.     trim (input_command);                 /* trim whitespace from user input */
  2343.     command = input_command [0];         /* command = 1st char input by user */
  2344.     command = toupper (command);              /* convert lower to upper case */
  2345.     VioWrtNChar(" ",80,22,0,hvio);
  2346.     VioWrtNChar(" ",80,23,0,hvio);
  2347.     VioWrtNChar(" ",80,24,0,hvio);
  2348.     
  2349.     switch (command)        /* take action according to code entered by user */
  2350.     {
  2351.       case 'T' :
  2352.         get_title (rec1_ptr->title);
  2353.         break;
  2354.         
  2355.       case 'Y' :
  2356.         get_year (rec1_ptr->year);
  2357.         break;
  2358.  
  2359.       case 'S' :
  2360.         get_subject (&rec1_ptr->subject);
  2361.         break;
  2362.         
  2363.       case 'F' :
  2364.         get_form (&rec1_ptr->form);
  2365.         break;                  
  2366.         
  2367.       case 'R' :
  2368.         get_rating (&rec1_ptr->rating);
  2369.         break;
  2370.         
  2371.       case 'M' :
  2372.         get_mpaa_code (&rec1_ptr->mpaa_code);
  2373.         break;
  2374.         
  2375.       case '1' :
  2376.         get_name (rec1_ptr->star1, "Star 1");
  2377.         break;
  2378.           
  2379.       case '2' :
  2380.         get_name (rec1_ptr->star2, "Star 2");
  2381.         break;
  2382.           
  2383.       case '3' :
  2384.         get_name (rec1_ptr->star3, "Star 3");
  2385.         break;
  2386.           
  2387.       case 'D' :
  2388.         get_name (rec1_ptr->director, "Director");
  2389.         break;
  2390.           
  2391.       case 'C' :
  2392.         get_loc (rec1_ptr->loc1, "Cassette No. ");
  2393.         break;
  2394.         
  2395.       case 'I' :
  2396.         get_loc (rec1_ptr->loc2, "Index No. ");
  2397.         break;
  2398.         
  2399.       case 'Q' :
  2400.         break;
  2401.         
  2402.       default  :
  2403.         VioSetCurPos(22,0,hvio);
  2404.         printf (" Invalid Code                    ");
  2405.         VioSetCurPos(23,0,hvio);
  2406.         pause();
  2407.         break;
  2408.     }
  2409.   }
  2410.  
  2411.   VioWrtNChar(" ",80,22,0,hvio);
  2412.   VioWrtNChar(" ",80,23,0,hvio);
  2413.   VioWrtNChar(" ",80,24,0,hvio);
  2414.   VioSetCurPos(22,0,hvio);
  2415.   free (char_buff);
  2416.  
  2417.   if (verify ())                                    /* if verified by user - */
  2418.     {
  2419.       VioSetCurPos(23,0,hvio);
  2420.       printf (" Record VERIFIED - add to transaction list.");
  2421.       VioSetCurPos(24,0,hvio);
  2422.       pause();
  2423.       clear_screen (LWHITE, BLUE);          /* - clear screen & reset colors */
  2424.       set_border (BLACK);                            /* - reset border color */
  2425.       return TRUE;                                    /* - return TRUE value */
  2426.     }
  2427.   else                                          /* if not verified by user - */
  2428.     {
  2429.       VioSetCurPos(23,0,hvio);
  2430.       printf (" Record NOT verified - discard.                ");
  2431.       VioSetCurPos(24,1,hvio);
  2432.       pause();
  2433.       clear_screen (LWHITE, BLUE);          /* - clear screen & reset colors */
  2434.       set_border (BLACK);                            /* - reset border color */
  2435.       return FALSE;                                  /* - return FALSE value */
  2436.  
  2437.     }
  2438. }
  2439.  
  2440. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ get_change ^^^^*/
  2441.  
  2442. #pragma subtitle("get_data()")
  2443. #pragma page()
  2444.  
  2445. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv get_data vvvv*/
  2446.  
  2447. /*----------------------------------------------------------------------------+
  2448. |                                                                             |
  2449. | SYNOPSIS                                                                    |
  2450. | ~~~~~~~~                                                                    |
  2451. |   #include <stdio.h>                                                        |
  2452. |   #include <string.h>                                                       |
  2453. |   #include <dos.h>                                                          |
  2454. |   int get_data (struct MOVIETRANS *trans_ptr)                               |
  2455. |                                                                             |
  2456. | FUNCTION                                                                    |
  2457. | ~~~~~~~~                                                                    |
  2458. |   Gets data from user to complete content of transaction pointer            |
  2459. |   requests user verification, and returns result of verification.           |
  2460. |                                                                             |
  2461. | RETURNS                                                                     |
  2462. | ~~~~~~~                                                                     |
  2463. |   TRUE (defined in videocat) if user verifies record; otherwise             |
  2464. |   returns false.                                                            |
  2465. |                                                                             |
  2466. |                                                                             |
  2467. | NOTES                                                                       |
  2468. | ~~~~~                                                                       |
  2469. |   Calls program functions which use MSC extensions; may not be portable     |
  2470. |   accross compilers and operating systems.                                  |
  2471. |                                                                             |
  2472. |                                                                             |
  2473. +----------------------------------------------------------------------------*/
  2474.  
  2475. int get_data (trans_ptr)                               /* get data from user */
  2476.  
  2477.   struct MOVIETRANS    *trans_ptr;                 /* pointer to transaction */
  2478.  
  2479. {
  2480.   USHORT                cbString;                       /* string byte count */
  2481.   char                 *char_buff;                          /* string buffer */
  2482.   extern void           clear_screen(); /* func to clear screen & set colors */
  2483.   extern void           display();       /* func displays contents of record */
  2484.   extern void           get_form();              /* func gets form from user */
  2485.   extern void           get_loc();           /* func gets location from user */
  2486.   extern void           get_mpaa_code();              /* func gets mpaa code */
  2487.   extern void           get_name();              /* func gets name from user */
  2488.   extern void           get_rating();          /* func gets rating from user */
  2489.   extern void           get_subject();        /* func gets subject from user */
  2490.   extern void           get_title();            /* func gets title from user */
  2491.   extern void           get_year();              /* func gets year from user */
  2492.   HVIO                  hvio = 0;                            /* video handle */
  2493.   extern char           pause();                     /* func pauses for user */
  2494.   struct MOVIERECORD    *rec_ptr;                /* pointer to a data record */
  2495.   extern void           set_border();       /* func sets screen border color */
  2496.   extern void           set_cursor();           /* func sets cursor position */
  2497.   extern int            verify();            /* func gets data verification  */
  2498.  
  2499.   char_buff = (char *) calloc (1, 0x100);
  2500.   rec_ptr = &trans_ptr->moviedata;  /* set pointer to record in trans struct */
  2501.   
  2502.             /* set up screen display */
  2503.               
  2504.   clear_screen (LWHITE,BLACK);                  /* clear screen & set colors */
  2505.   window (0,79,0,21,LWHITE,BLUE);
  2506.   window (22,61,3,19,BLACK,BLACK);
  2507.   window (20,59,2,18,BLACK,WHITE);
  2508.   set_border (BLUE);                              /* set screen border color */
  2509.   VioSetCurPos (22,0,hvio);                               /* position cursor */
  2510.  
  2511.             /* display message and wait for user */
  2512.             
  2513.  
  2514.   clear_screen (LWHITE,BLACK);                  /* clear screen & set colors */
  2515.   window (0,79,0,21,LWHITE,BLUE);
  2516.   window (6,78,9,14,BLACK,BLACK);
  2517.   window (4,76,8,13,BLACK,WHITE);
  2518.   sprintf (char_buff, "Prepare to enter data for a video record...");
  2519.   cbString = (USHORT)strlen(char_buff);
  2520.   VioWrtCharStr (char_buff,cbString,11,9,hvio);
  2521.   set_border (BLUE);                              /* set screen border color */
  2522.   VioSetCurPos (22,0,hvio);                               /* position cursor */
  2523.   pause();
  2524.  
  2525.             /* get data from user */
  2526.             
  2527.   clear_screen (BLACK, WHITE);                               /* clear screen */
  2528.   get_title (rec_ptr->title);                         /* get title from user */
  2529.   get_year (rec_ptr->year);                            /* get year from user */
  2530.   if (trans_ptr->transaction != 'D')        /* if not a delete transaction - */
  2531.     {
  2532.       get_name (rec_ptr->star1, "Star 1");                /* get star 1 name */
  2533.       get_name (rec_ptr->star2, "Star 2");                /* get star 2 name */
  2534.       get_name (rec_ptr->star3, "Star 3");                /* get star 3 name */
  2535.       get_name (rec_ptr->director, "Director");            /*  director name */
  2536.       get_subject (&rec_ptr->subject);                        /* get subject */
  2537.       get_form (&rec_ptr->form);                                 /* get form */
  2538.       get_mpaa_code (&rec_ptr->mpaa_code);                  /* get mpaa code */
  2539.       get_rating (&rec_ptr->rating);                           /* get rating */
  2540.       get_loc (rec_ptr->loc1, "Cassette No. ");            /* get cassette # */
  2541.       get_loc (rec_ptr->loc2, "Index No. ");                /* get index no. */
  2542.     }    
  2543.     
  2544.         /* display data entered & get user verification */
  2545.         
  2546.   clear_screen (LWHITE,BLACK);                  /* clear screen & set colors */
  2547.   window (0,79,0,20,LWHITE,BLUE);
  2548.   window (6,78,9,14,BLACK,BLACK);
  2549.   window (4,76,8,13,BLACK,WHITE);
  2550.   set_border (BLUE);                              /* set screen border color */
  2551.   VioSetCurPos (21,0,hvio);                               /* position cursor */
  2552.   display (8, trans_ptr);                          /* display record content */
  2553.   
  2554.   if (verify ())                                    /* if verified by user - */
  2555.     {
  2556.       VioSetCurPos(22,0,hvio);
  2557.       printf (" Record VERIFIED - add to transaction list.");
  2558.       VioSetCurPos(23,1,hvio);
  2559.       pause();
  2560.       clear_screen (LWHITE, BLUE);          /* - clear screen & reset colors */
  2561.       set_border (BLACK);                            /* - reset border color */
  2562.       free (char_buff);
  2563.       return TRUE;                                    /* - return TRUE value */
  2564.     }
  2565.   else                                          /* if not verified by user - */
  2566.     {
  2567.       VioSetCurPos(22,0,hvio);
  2568.       printf (" Record NOT verified - discard.                ");
  2569.       VioSetCurPos(23,1,hvio);
  2570.       pause();
  2571.       clear_screen (LWHITE, BLUE);          /* - clear screen & reset colors */
  2572.       set_border (BLACK);                            /* - reset border color */
  2573.       free (char_buff);
  2574.       return FALSE;                                  /* - return FALSE value */
  2575.     }
  2576. }
  2577.  
  2578. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ get_data ^^^^*/
  2579.  
  2580. #pragma subtitle("get_delete()")
  2581. #pragma page()
  2582.                                                
  2583. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv get_delete vvvv*/
  2584.  
  2585. /*----------------------------------------------------------------------------+
  2586. |                                                                             |
  2587. | SYNOPSIS                                                                    |
  2588. | ~~~~~~~~                                                                    |
  2589. |   #include <stdio.h>                                                        |
  2590. |   #include <string.h>                                                       |
  2591. |   #include <dos.h>                                                          |
  2592. |   int get_delete (struct MOVIETRANS *trans1_ptr, *trans2_ptr,               |
  2593. |                   char *base_file_id)                                       |
  2594. | FUNCTION                                                                    |
  2595. | ~~~~~~~~                                                                    |
  2596. |   Delete an existing record in the base file.  Prompts user to identify     |
  2597. |   record to be deleted by title and year; searches for record; if found,    |
  2598. |   stores it at trans2_ptr as a delete transactions.                         |
  2599. |                                                                             |
  2600. | RETURNS                                                                     |
  2601. | ~~~~~~~                                                                     |
  2602. |   TRUE (defined in videocat) if record to be deleted is successfully        |
  2603. |   located and verified by the user; otherwise returns FALSE.                |
  2604. |                                                                             |
  2605. |                                                                             |
  2606. | NOTES                                                                       |
  2607. | ~~~~~                                                                       |
  2608. |   Calls program functions which use MSC extensions; may not be portable     |
  2609. |   accross compilers and operating systems.                                  |
  2610. |                                                                             |
  2611. |                                                                             |
  2612. +----------------------------------------------------------------------------*/
  2613.  
  2614. int get_delete (trans1_ptr, trans2_ptr, base_file_id) /* get & delete record */
  2615.  
  2616.   struct MOVIETRANS    *trans1_ptr, *trans2_ptr;  /* pointers to trans buffs */
  2617.   char                 *base_file_id;               /* file id for base file */
  2618. {
  2619.   FILE                 *basef_ptr;                       /* ptr to base file */
  2620.   USHORT                cbString;                       /* string byte count */
  2621.   char                 *char_buff;                          /* string buffer */
  2622.   extern void           clear_screen(); /* func to clear screen & set colors */
  2623.   extern void           display();       /* func displays contents of record */
  2624.   int                   found = FALSE;      /* boolean flag for record found */
  2625.   extern void           get_title();            /* func gets title from user */
  2626.   extern void           get_year();              /* func gets year from user */
  2627.   HVIO                  hvio = 0;                            /* video handle */
  2628.   char                 *iobuf;                        /* buffer for file i/o */
  2629.   extern char           pause();                     /* func pauses for user */
  2630.   struct MOVIERECORD   *rec1_ptr;                /* pointer to a data record */
  2631.   struct MOVIERECORD   *rec2_ptr;                /* pointer to a data record */
  2632.   extern void           set_border();       /* func sets screen border color */
  2633.   extern void           set_cursor();           /* func sets cursor position */
  2634.   int                   tcomp_result;          /* result of title comparison */
  2635.   extern int            verify();            /* func gets data verification  */
  2636.   int                   ycomp_result;            /*result of year comparison */
  2637.  
  2638.   char_buff = (char *) calloc (1, 0x100);
  2639.   rec1_ptr = &trans1_ptr->moviedata;     /* set record pointers to data recs */
  2640.   rec2_ptr = &trans2_ptr->moviedata;            /* in transaction structures */
  2641.   iobuf = calloc (1, BIGBUFF);              /* allocate memory to i/o buffer */
  2642.  
  2643.  
  2644.  
  2645.  
  2646.             /* set up screen display */
  2647.               
  2648.   clear_screen (LWHITE,BLACK);                  /* clear screen & set colors */
  2649.   window (0,79,0,21,LWHITE,BLUE);
  2650.   window (22,61,3,19,BLACK,BLACK);
  2651.   window (20,59,2,18,BLACK,WHITE);
  2652.   set_border (BLUE);                              /* set screen border color */
  2653.   VioSetCurPos (22,0,hvio);                               /* position cursor */
  2654.  
  2655.             /* display message and wait for user */
  2656.             
  2657.  
  2658.   clear_screen (LWHITE,BLACK);                  /* clear screen & set colors */
  2659.   window (0,79,0,21,LWHITE,BLUE);
  2660.   window (6,78,9,14,BLACK,BLACK);
  2661.   window (4,76,8,13,BLACK,WHITE);
  2662.   sprintf (char_buff, "Prepare to enter data to delete a video record.");
  2663.   cbString = (USHORT)strlen(char_buff);
  2664.   VioWrtCharStr (char_buff,cbString,10,9,hvio);
  2665.   sprintf (char_buff, "Title and year must match an existing record...");
  2666.   cbString = (USHORT)strlen(char_buff);
  2667.   VioWrtCharStr (char_buff,cbString,11,9,hvio);
  2668.   set_border (BLUE);                              /* set screen border color */
  2669.   VioSetCurPos (22,0,hvio);                               /* position cursor */
  2670.   pause();
  2671.  
  2672.  
  2673.            /* identify record to be changed */
  2674.  
  2675.   get_title (rec1_ptr->title);                        /* get title from user */
  2676.   get_year (rec1_ptr->year);                           /* get year from user */
  2677.   basef_ptr = fopen (base_file_id, "rb");                  /* open base file */
  2678.   setvbuf (basef_ptr, iobuf, _IOFBF, BIGBUFF);         /* set big i/o buffer */
  2679.   clear_screen (LWHITE,BLACK);                  /* clear screen & set colors */
  2680.   window (0,79,0,21,LWHITE,BLUE);
  2681.   window (6,78,9,14,BLACK,BLACK);
  2682.   window (4,76,8,13,BLACK,WHITE);
  2683.   sprintf (char_buff, "Searching for record to be deleted.............");
  2684.   cbString = (USHORT)strlen(char_buff);
  2685.   VioWrtCharStr (char_buff,cbString,10,9,hvio);
  2686.   set_border (BLUE);                              /* set screen border color */
  2687.   VioSetCurPos (22,0,hvio);                               /* position cursor */
  2688.  
  2689.      
  2690.      /* search base file for record with matching title and year */
  2691.        
  2692.   if (basef_ptr == NULL)                                  /* if open error - */
  2693.   {
  2694.     printf (" Error in attempting to open base file.\n");       /* warn user */
  2695.     pause();
  2696.     return FALSE;                                          /* & return error */
  2697.   }
  2698.   while ((!(feof (basef_ptr))) && (!(found))) /* while not EOF and not found */
  2699.   {
  2700.     if ((fread ((char *)&trans2_ptr->moviedata, sizeof(struct MOVIERECORD),
  2701.        1, basef_ptr)) != 1)                                 /* read a record */
  2702.     {                                                     /* if read error - */
  2703.       if (feof(basef_ptr))                            /* - if EOF break loop */
  2704.         break;                          /*   and continue (normal condition) */
  2705.       else 
  2706.       {                                           /* - if other read error - */
  2707.         printf (" Error in reading base file.\n");              /* warn user */
  2708.         pause();                                            /* wait for user */
  2709.         break;                      /* break off search (abnormal condition) */
  2710.       }
  2711.     }
  2712.     tcomp_result = strcmp (rec1_ptr->title,                /* compare search */
  2713.         rec2_ptr->title);                          /* title and record title */
  2714.     if (tcomp_result < 0)         /* if record is past targed in alpha order */
  2715.       break;                        /* break, no need to search rest of file */
  2716.     ycomp_result = strcmp (rec1_ptr->year,                  /*compare search */
  2717.         rec2_ptr->year);                             /* year and record year */
  2718.     if ((tcomp_result == 0) && (ycomp_result == 0))    /* if both title and  */
  2719.       {                                            /* year are exact matches */
  2720.         found = TRUE;                          /* then target has been found */
  2721.         break;                      /* break, no need to search rest of file */
  2722.       }
  2723.   }
  2724.   fclose (basef_ptr);                                     /* close base file */
  2725.   free (iobuf);                       /* free memory allocated to i/o buffer */
  2726.   
  2727.      /* process change of matching record, if found */
  2728.  
  2729.   if (!(found))                              /* if matching record not found */
  2730.   {
  2731.     printf (" Record not found.\n");                            /* warn user */
  2732.     pause();                                                /* wait for user */
  2733.     return FALSE;                                     /* return error result */
  2734.   }  
  2735.   trans2_ptr->transaction = 'D';          /* code buffer 2 as a delete trans */
  2736.  
  2737.  
  2738.      
  2739.   clear_screen (LWHITE,BLACK);                  /* clear screen & set colors */
  2740.   window (0,79,0,21,WHITE,BLUE);
  2741.   window (0,79,0,0,LWHITE,BLUE);
  2742.   window (6,78,2,5,BLACK,BLACK);
  2743.   window (4,76,1,4,BLACK,WHITE);
  2744.   set_border (BLUE);                              /* set screen border color */
  2745.   display (0, trans2_ptr);           /* display current content of add trans */
  2746.   VioSetCurPos (23,0,hvio);                               /* position cursor */
  2747.       
  2748.      
  2749.      
  2750.   VioWrtNChar(" ",80,22,0,hvio);
  2751.   VioWrtNChar(" ",80,23,0,hvio);
  2752.   VioWrtNChar(" ",80,24,0,hvio);
  2753.   VioSetCurPos(22,0,hvio);
  2754.  
  2755.   if (verify ())                                    /* if verified by user - */
  2756.     {
  2757.       VioSetCurPos(23,0,hvio);
  2758.       printf (" Delete VERIFIED - add to transaction list.");
  2759.       VioSetCurPos(24,0,hvio);
  2760.       pause();
  2761.       free (char_buff);
  2762.       clear_screen (LWHITE, BLUE);          /* - clear screen & reset colors */
  2763.       set_border (BLACK);                            /* - reset border color */
  2764.       return TRUE;                                    /* - return TRUE value */
  2765.     }
  2766.   else                                          /* if not verified by user - */
  2767.     {
  2768.       VioSetCurPos(23,0,hvio);
  2769.       printf (" Delete NOT verified - discard.                ");
  2770.       VioSetCurPos(24,0,hvio);
  2771.       pause();
  2772.       clear_screen (LWHITE, BLUE);          /* - clear screen & reset colors */
  2773.       set_border (BLACK);                            /* - reset border color */
  2774.       free (char_buff);
  2775.       return FALSE;                                  /* - return FALSE value */
  2776.  
  2777.     }
  2778.      
  2779. }
  2780.  
  2781. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ get_delete ^^^^*/
  2782.  
  2783. #pragma subtitle("get_form()")
  2784. #pragma page()
  2785.  
  2786.  
  2787. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv get_form vvvv*/
  2788.  
  2789. /*----------------------------------------------------------------------------+
  2790. |                                                                             |
  2791. | SYNOPSIS                                                                    |
  2792. | ~~~~~~~~                                                                    |
  2793. |   #include <stdio.h>                                                        |
  2794. |   #include <string.h>                                                       |
  2795. |   #include <ctype.h>                                                        |
  2796. |   void get_form (char *form_ptr)                                            |
  2797. |                                                                             |
  2798. | FUNCTION                                                                    |
  2799. | ~~~~~~~~                                                                    |
  2800. |   Calls function list_forms () to display form codes and explanations,      |
  2801. |   prompts user to enter a selected code, checks the code entered against    |
  2802. |   the codes in the global array codes[] for validity, repeats prompt if     |
  2803. |   not valid, otherwise puts character in the byte pointed to by form_ptr.   |
  2804. | RETURNS                                                                     |
  2805. | ~~~~~~~                                                                     |
  2806. |   Nothing.                                                                  |
  2807. |                                                                             |
  2808. |                                                                             |
  2809. |                                                                             |
  2810. | NOTES                                                                       |
  2811. | ~~~~~                                                                       |
  2812. |   Accesses the global array codes[].                                        |
  2813. |                                                                             |
  2814. |                                                                             |
  2815. |                                                                             |
  2816. +----------------------------------------------------------------------------*/
  2817.  
  2818. void get_form (form_ptr)                    /* func gets form code from user */
  2819.  
  2820.   char                 *form_ptr;            /* ptr to storage for form code */
  2821.  
  2822. {
  2823.   USHORT                cbString;                       /* string byte Count */
  2824.   char                 *char_buff;                          /* string buffer */ 
  2825.   int                   count;                                    /* counter */
  2826.   HVIO                  hvio = 0;                            /* video handle */
  2827.   char                  input_form [INPUTLENGTH];       /* user input buffer */
  2828.   extern void           trim();        /* func trims lead & trail whitespace */
  2829.   int                   valid_code = FALSE;            /* validity test flag */
  2830.   extern void           window();            /* function opens screen window */
  2831.  
  2832.   char_buff = (char *) calloc (1, 0x100);
  2833.   while (!valid_code)                      /* while valid code not entered - */
  2834.   {
  2835.    clear_screen (LWHITE,BLACK);                 /* clear screen & set colors */
  2836.    window (0,79,0,21,LWHITE,BLUE);
  2837.  
  2838.  
  2839.    window (16,39,1,14,BLUE,BLACK);
  2840.    window (15,38,0,13,BLACK,WHITE);
  2841.    VioWrtNChar ("\xDC",24,14,16,hvio);
  2842.  
  2843.    window (42,65,1,14,BLUE,BLACK);
  2844.    window (41,64,0,13,BLACK,WHITE);
  2845.    VioWrtNChar ("\xDC",24,14,42,hvio);
  2846.  
  2847.    set_border (BLUE);                              /* set screen border color */
  2848.    VioSetCurPos (22,0,hvio);                               /* position cursor */
  2849.  
  2850.      /* print top border of table */
  2851.  
  2852.    sprintf (char_buff,"               %c", 201);
  2853.    cbString = (USHORT)strlen(char_buff);
  2854.    VioWrtCharStr(char_buff,cbString,0,0,hvio);
  2855.    for (count = 0; count < 22; count++)
  2856.    {
  2857.       sprintf (char_buff,"%c", 205);
  2858.       cbString = (USHORT)strlen(char_buff);
  2859.       VioWrtCharStr (char_buff,cbString,0,(count + 16),hvio);
  2860.    }
  2861.    sprintf (char_buff,"%c  %c", 187, 201);
  2862.    cbString = (USHORT)strlen(char_buff);
  2863.    VioWrtCharStr(char_buff,cbString,0,38,hvio);
  2864.    for (count = 0; count < 22; count++)
  2865.    {
  2866.       sprintf (char_buff,"%c", 205);
  2867.       cbString = (USHORT)strlen(char_buff);
  2868.       VioWrtCharStr (char_buff,cbString,0,(count + 42),hvio);
  2869.    }
  2870.    sprintf (char_buff,"%c", 187);
  2871.    cbString = (USHORT)strlen(char_buff);
  2872.    VioWrtCharStr(char_buff,cbString,0,64,hvio);
  2873.  
  2874.         /* print main body of table */
  2875.  
  2876.    sprintf (char_buff,"               %c A = Adventure        %c",  186, 186);
  2877.    cbString = (USHORT)strlen(char_buff);
  2878.    VioWrtCharStr(char_buff,cbString,1,0,hvio);
  2879.    sprintf (char_buff,             "  %c M = Intrigue         %c",  186, 186);
  2880.    cbString = (USHORT)strlen(char_buff);  
  2881.    VioWrtCharStr(char_buff,cbString,1,39,hvio);
  2882.  
  2883.    sprintf (char_buff,"               %c B = Classic          %c",  186, 186);
  2884.    cbString = (USHORT)strlen(char_buff);
  2885.    VioWrtCharStr(char_buff,cbString,2,0,hvio);
  2886.    sprintf (char_buff,             "  %c N = Melodrama        %c",  186, 186);
  2887.    cbString = (USHORT)strlen(char_buff);
  2888.    VioWrtCharStr(char_buff,cbString,2,39,hvio);
  2889.  
  2890.    sprintf (char_buff,"               %c C = Comedy           %c",  186, 186);
  2891.    cbString = (USHORT)strlen(char_buff);
  2892.    VioWrtCharStr(char_buff,cbString,3,0,hvio);
  2893.    sprintf (char_buff,             "  %c O = Mystery          %c",  186, 186);
  2894.    cbString = (USHORT)strlen(char_buff);
  2895.    VioWrtCharStr(char_buff,cbString,3,39,hvio);
  2896.  
  2897.    sprintf (char_buff,"               %c D = Comedy-Drama     %c",  186, 186);
  2898.    cbString = (USHORT)strlen(char_buff);
  2899.    VioWrtCharStr(char_buff,cbString,4,0,hvio);
  2900.    sprintf (char_buff,             "  %c P = One-man-show     %c",  186, 186);
  2901.    cbString = (USHORT)strlen(char_buff);
  2902.    VioWrtCharStr(char_buff,cbString,4,39,hvio);
  2903.  
  2904.    sprintf (char_buff,"               %c E = Compilation      %c",  186, 186);
  2905.    cbString = (USHORT)strlen(char_buff);
  2906.    VioWrtCharStr(char_buff,cbString,5,0,hvio);
  2907.    sprintf (char_buff,             "  %c Q = Opera            %c",  186, 186);
  2908.    cbString = (USHORT)strlen(char_buff);
  2909.    VioWrtCharStr(char_buff,cbString,5,39,hvio);
  2910.  
  2911.    sprintf (char_buff,"               %c F = Concert          %c",  186, 186);
  2912.    cbString = (USHORT)strlen(char_buff);          
  2913.    VioWrtCharStr(char_buff,cbString,6,0,hvio);
  2914.    sprintf (char_buff,             "  %c R = Revue            %c",  186, 186);
  2915.    cbString = (USHORT)strlen(char_buff);
  2916.    VioWrtCharStr(char_buff,cbString,6,39,hvio);
  2917.  
  2918.    sprintf (char_buff,"               %c G = Documentary      %c",  186, 186);
  2919.    cbString = (USHORT)strlen(char_buff);
  2920.    VioWrtCharStr(char_buff,cbString,7,0,hvio);
  2921.    sprintf (char_buff,             "  %c S = Romance          %c",  186, 186);
  2922.    cbString = (USHORT)strlen(char_buff);
  2923.    VioWrtCharStr(char_buff,cbString,7,39,hvio);
  2924.  
  2925.    sprintf (char_buff,"               %c H = Docu-Drama       %c",  186, 186);
  2926.    cbString = (USHORT)strlen(char_buff);
  2927.    VioWrtCharStr(char_buff,cbString,8,0,hvio);
  2928.    sprintf (char_buff,             "  %c T = Satire           %c",  186, 186);
  2929.    cbString = (USHORT)strlen(char_buff);
  2930.    VioWrtCharStr(char_buff,cbString,8,39,hvio);
  2931.  
  2932.  
  2933.    sprintf (char_buff,"               %c I = Drama            %c",  186, 186);
  2934.    cbString = (USHORT)strlen(char_buff);
  2935.    VioWrtCharStr(char_buff,cbString, 9,0,hvio);
  2936.    sprintf (char_buff,             "  %c U = Spoof            %c",  186, 186);
  2937.    cbString = (USHORT)strlen(char_buff);
  2938.    VioWrtCharStr(char_buff,cbString, 9,39,hvio);
  2939.  
  2940.    sprintf (char_buff,"               %c J = Epic             %c",  186, 186);
  2941.    cbString = (USHORT)strlen(char_buff);
  2942.    VioWrtCharStr(char_buff,cbString,10,0,hvio);
  2943.    sprintf (char_buff,             "  %c V = Story            %c",  186, 186);
  2944.    cbString = (USHORT)strlen(char_buff);
  2945.    VioWrtCharStr(char_buff,cbString,10,39,hvio);
  2946.  
  2947.    sprintf (char_buff,"               %c K = Fantasy          %c",  186, 186);
  2948.    cbString = (USHORT)strlen(char_buff);
  2949.    VioWrtCharStr(char_buff,cbString,11,0,hvio);
  2950.    sprintf (char_buff,             "  %c W = Thriller         %c",  186, 186);
  2951.    cbString = (USHORT)strlen(char_buff);
  2952.    VioWrtCharStr(char_buff,cbString,11,39,hvio);
  2953.  
  2954.    sprintf (char_buff,"               %c L = Farce            %c",  186, 186);
  2955.    cbString = (USHORT)strlen(char_buff);
  2956.    VioWrtCharStr(char_buff,cbString,12,0,hvio);
  2957.    sprintf (char_buff,             "  %c X = Variety          %c",  186, 186);
  2958.    cbString = (USHORT)strlen(char_buff);
  2959.    VioWrtCharStr(char_buff,cbString,12,39,hvio);
  2960.  
  2961.  
  2962.             /* print bottom border of table */
  2963.              
  2964.  
  2965.  
  2966.    sprintf (char_buff,"               %c", 200);
  2967.    cbString = (USHORT)strlen(char_buff);
  2968.    VioWrtCharStr(char_buff,cbString,13,0,hvio);
  2969.    for (count = 0; count < 22; count++)
  2970.    {
  2971.       sprintf (char_buff,"%c", 205);
  2972.       cbString = (USHORT)strlen(char_buff);
  2973.       VioWrtCharStr (char_buff,cbString,13,(count + 16),hvio);
  2974.    }
  2975.    sprintf (char_buff,"%c  %c", 188, 200);
  2976.    cbString = (USHORT)strlen(char_buff);
  2977.    VioWrtCharStr(char_buff,cbString,13,38,hvio);
  2978.    for (count = 0; count < 22; count++)
  2979.    {
  2980.       sprintf (char_buff,"%c", 205);
  2981.       cbString = (USHORT)strlen(char_buff);
  2982.       VioWrtCharStr (char_buff,cbString,13,(count + 42),hvio);
  2983.    }
  2984.    sprintf (char_buff,"%c", 188);
  2985.    cbString = (USHORT)strlen(char_buff);
  2986.    VioWrtCharStr(char_buff,cbString,13,64,hvio);
  2987.  
  2988.  
  2989.                    /*  get user response */
  2990.  
  2991.    VioSetCurPos (23,0,hvio);        
  2992.    printf (" Form code -> ");                       /* prompt user for input */
  2993.    gets (input_form);                                      /* get user input */
  2994.    trim (input_form);                                     /* trim user input */
  2995.    *form_ptr = toupper (input_form[0]);      /* move first character entered */
  2996.    for (count = 0; count < FORMNUMBER; count++)       /* compare with codes  */
  2997.    if (*form_ptr == codes[count])               /* list; if code found, then */
  2998.        valid_code = TRUE;                                   /* code is valid */
  2999.   }
  3000.   set_border (BLACK);
  3001.   free (char_buff);
  3002.  
  3003. }
  3004.  
  3005. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ get_form ^^^^*/
  3006.  
  3007. #pragma subtitle("get_loc()")
  3008. #pragma page()
  3009.  
  3010. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv get_loc vvvv*/
  3011.  
  3012. /*----------------------------------------------------------------------------+
  3013. |                                                                             |
  3014. | SYNOPSIS                                                                    |
  3015. | ~~~~~~~~                                                                    |
  3016. |   #include <stdio.h>                                                        |
  3017. |   #include <string.h>                                                       |
  3018. |   void get_loc (char *loc_ptr, *loc_for)                                    |
  3019. |                                                                             |
  3020. | FUNCTION                                                                    |
  3021. | ~~~~~~~~                                                                    |
  3022. |   Prompts the user to enter location for location describe by string        |
  3023. |   at *loc_for, gets user input, edits input, and copies to *loc_ptr.        |
  3024. |                                                                             |
  3025. | RETURNS                                                                     |
  3026. | ~~~~~~~                                                                     |
  3027. |   Nothing.                                                                  |
  3028. |                                                                             |
  3029. |                                                                             |
  3030. | NOTES                                                                       |
  3031. | ~~~~~                                                                       |
  3032. |   Uses macros defined in Videocat.   Otherwise uses only ANSI standard      |
  3033. |   functions and should be portable.  Uses string functions declared         |
  3034. |   in string.h.                                                              |
  3035. |                                                                             |
  3036. |                                                                             |
  3037. |                                                                             |
  3038. +----------------------------------------------------------------------------*/
  3039.   
  3040. void get_loc (loc_ptr, loc_for)                /* func to get name from user */
  3041.  
  3042.   char                 *loc_ptr;         /* place where name is to be stored */
  3043.   char                 *loc_for;                     /* whose name requested */
  3044.  
  3045. {
  3046.  
  3047.   USHORT                cbString;                       /* string byte count */
  3048.   char                 *char_buff;                          /* string buffer */
  3049.   extern void           editRdata();          /* func edits to record format */
  3050.   HVIO                  hvio = 0;                            /* video handle */
  3051.   char                  input_loc [INPUTLENGTH];          /* user input buff */
  3052.   extern void           set_border();              /* func sets border color */
  3053.   extern void           window();                /* func opens screen window */
  3054.  
  3055.  
  3056.   char_buff = (char *) calloc (1, 0x100);
  3057.   clear_screen (LWHITE,BLACK);                  /* clear screen & set colors */
  3058.   window (0,79,0,21,LWHITE,BLUE);
  3059.   window (6,78,9,14,BLACK,BLACK);
  3060.   window (4,76,8,13,BLACK,WHITE);
  3061.   sprintf (char_buff, "Please enter requested data....");
  3062.   cbString = (USHORT)strlen(char_buff);
  3063.   VioWrtCharStr (char_buff,cbString,11,9,hvio);
  3064.   set_border (BLUE);                              /* set screen border color */
  3065.   VioSetCurPos (22,0,hvio);                               /* position cursor */
  3066.   printf ("\n %s -> ", loc_for);            /* prompt user to enter location */
  3067.   gets (input_loc);                                        /* get user input */
  3068.   editRdata (input_loc, LOCLENGTH);      /* edit user input to record format */
  3069.   strcpy (loc_ptr, input_loc);               /* copy location to destination */
  3070.   set_border (BLACK);
  3071.   free (char_buff);
  3072.  
  3073. }
  3074.  
  3075. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ get_loc ^^^^*/
  3076.  
  3077. #pragma subtitle("get_mpaa_code()")
  3078. #pragma page()
  3079.  
  3080. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv get_mpaa_code vvvv*/
  3081.  
  3082. /*----------------------------------------------------------------------------+
  3083. |                                                                             |
  3084. | SYNOPSIS                                                                    |
  3085. | ~~~~~~~~                                                                    |
  3086. |   #include <stdio.h>                                                        |
  3087. |   #include <string.h>                                                       |
  3088. |   #include <ctype.h>                                                        |
  3089. |   void get_mpaa_code (char *mpaa_ptr)                                       |
  3090. |                                                                             |
  3091. | FUNCTION                                                                    |
  3092. | ~~~~~~~~                                                                    |
  3093. |   Calls function list_rates () to display rating codes and explanactions,   |
  3094. |   prompts user to enter a selected code, checks the code entered against    |
  3095. |   the codes in the global array mpaa_codes[] for validity,repeats prompt if |
  3096. |   not valid, otherwise puts character in the byte pointed to by rate_ptr.   |
  3097. | RETURNS                                                                     |
  3098. | ~~~~~~~                                                                     |
  3099. |   Nothing.                                                                  |
  3100. |                                                                             |
  3101. |                                                                             |
  3102. |                                                                             |
  3103. | NOTES                                                                       |
  3104. | ~~~~~                                                                       |
  3105. |   Accesses the global array mpaa_codes[].                                   |
  3106. |                                                                             |
  3107. |                                                                             |
  3108. |                                                                             |
  3109. +----------------------------------------------------------------------------*/
  3110.  
  3111. void get_mpaa_code (mpaa_ptr)             /* func gets rating code from user */
  3112.  
  3113.   char                 *mpaa_ptr;            /* ptr to storage for subj code */
  3114.  
  3115. {
  3116.   USHORT                cbString;                       /* string byte Count */
  3117.   char                 *char_buff;                          /* string buffer */ 
  3118.   int                   count;                                    /* counter */
  3119.   HVIO                  hvio = 0;                            /* video handle */
  3120.   char                  input_rate [INPUTLENGTH];       /* user input buffer */
  3121.   extern void           trim();        /* func trims lead & trail whitespace */
  3122.   int                   valid_code = FALSE;            /* validity test flag */
  3123.   extern void           window();            /* function opens screen window */
  3124.  
  3125.   char_buff = (char *) calloc (1, 0x100);
  3126.   while (!valid_code)                      /* while valid code not entered - */
  3127.   {
  3128.    clear_screen (LWHITE,BLACK);                 /* clear screen & set colors */
  3129.    window (0,79,0,21,LWHITE,BLUE);
  3130.  
  3131.  
  3132.    window (16,39,1,5,BLUE,BLACK);
  3133.    window (15,38,0,4,BLACK,WHITE);
  3134.    VioWrtNChar ("\xDC",24,5,16,hvio);
  3135.  
  3136.    window (42,65,1,5,BLUE,BLACK);
  3137.    window (41,64,0,4,BLACK,WHITE);
  3138.    VioWrtNChar ("\xDC",24,5,42,hvio);
  3139.                                            
  3140.    set_border (BLUE);                             /* set screen border color */
  3141.    VioSetCurPos (22,0,hvio);                              /* position cursor */
  3142.  
  3143.      /* print top border of table */
  3144.  
  3145.    sprintf (char_buff,"               %c", 201);
  3146.    cbString = (USHORT)strlen(char_buff);
  3147.    VioWrtCharStr(char_buff,cbString,0,0,hvio);
  3148.    for (count = 0; count < 22; count++)
  3149.    {
  3150.       sprintf (char_buff,"%c", 205);
  3151.       cbString = (USHORT)strlen(char_buff);
  3152.       VioWrtCharStr (char_buff,cbString,0,(count + 16),hvio);
  3153.    }
  3154.    sprintf (char_buff,"%c  %c", 187, 201);
  3155.    cbString = (USHORT)strlen(char_buff);
  3156.    VioWrtCharStr(char_buff,cbString,0,38,hvio);
  3157.    for (count = 0; count < 22; count++)
  3158.    {
  3159.       sprintf (char_buff,"%c", 205);
  3160.       cbString = (USHORT)strlen(char_buff);
  3161.       VioWrtCharStr (char_buff,cbString,0,(count + 42),hvio);
  3162.    }
  3163.    sprintf (char_buff,"%c", 187);
  3164.    cbString = (USHORT)strlen(char_buff);
  3165.    VioWrtCharStr(char_buff,cbString,0,64,hvio);
  3166.  
  3167.         /* print main body of table */
  3168.  
  3169.    sprintf (char_buff,"               %c A = MPAA G     Rated %c",  186, 186);
  3170.    cbString = (USHORT)strlen(char_buff);
  3171.    VioWrtCharStr(char_buff,cbString,1,0,hvio);
  3172.    sprintf (char_buff,             "  %c D = MPAA R     Rated %c",  186, 186);
  3173.    cbString = (USHORT)strlen(char_buff);  
  3174.    VioWrtCharStr(char_buff,cbString,1,39,hvio);
  3175.  
  3176.    sprintf (char_buff,"               %c B = MPAA PG    Rated %c",  186, 186);
  3177.    cbString = (USHORT)strlen(char_buff);
  3178.    VioWrtCharStr(char_buff,cbString,2,0,hvio);
  3179.    sprintf (char_buff,             "  %c E = MPAA X     Rated %c",  186, 186);
  3180.    cbString = (USHORT)strlen(char_buff);
  3181.    VioWrtCharStr(char_buff,cbString,2,39,hvio);
  3182.  
  3183.    sprintf (char_buff,"               %c C = MPAA PG13  Rated %c",  186, 186);
  3184.    cbString = (USHORT)strlen(char_buff);
  3185.    VioWrtCharStr(char_buff,cbString,3,0,hvio);
  3186.    sprintf (char_buff,             "  %c F = MPAA Not   Rated %c",  186, 186);
  3187.    cbString = (USHORT)strlen(char_buff);
  3188.    VioWrtCharStr(char_buff,cbString,3,39,hvio);
  3189.  
  3190.  
  3191.  
  3192.             /* print bottom border of table */
  3193.              
  3194.  
  3195.  
  3196.    sprintf (char_buff,"               %c", 200);
  3197.    cbString = (USHORT)strlen(char_buff);
  3198.    VioWrtCharStr(char_buff,cbString,4,0,hvio);
  3199.    for (count = 0; count < 22; count++)
  3200.    {
  3201.       sprintf (char_buff,"%c", 205);
  3202.       cbString = (USHORT)strlen(char_buff);
  3203.       VioWrtCharStr (char_buff,cbString,4,(count + 16),hvio);
  3204.    }
  3205.    sprintf (char_buff,"%c  %c", 188, 200);
  3206.    cbString = (USHORT)strlen(char_buff);
  3207.    VioWrtCharStr(char_buff,cbString,4,38,hvio);
  3208.    for (count = 0; count < 22; count++)
  3209.    {
  3210.       sprintf (char_buff,"%c", 205);
  3211.       cbString = (USHORT)strlen(char_buff);
  3212.       VioWrtCharStr (char_buff,cbString,4,(count + 42),hvio);
  3213.    }
  3214.    sprintf (char_buff,"%c", 188);
  3215.    cbString = (USHORT)strlen(char_buff);
  3216.    VioWrtCharStr(char_buff,cbString,4,64,hvio);
  3217.  
  3218.  
  3219.                    /*  get user response */
  3220.  
  3221.    VioSetCurPos (23,0,hvio);        
  3222.    printf (" MPAA code -> ");                       /* prompt user for input */
  3223.    gets (input_rate);                                      /* get user input */
  3224.    trim (input_rate);                                     /* trim user input */
  3225.    *mpaa_ptr = toupper (input_rate[0]);      /* move first character entered */
  3226.    for (count = 0; count < MPAANUMBER; count++)       /* compare with codes  */
  3227.      if (*mpaa_ptr == codes[count])             /* list; if code found, then */
  3228.               valid_code = TRUE;                            /* code is valid */
  3229.   }
  3230.   set_border (BLACK);
  3231.   free (char_buff);
  3232.  
  3233. }
  3234.  
  3235.  
  3236. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ get_mpaa_code ^^^^*/
  3237.  
  3238. #pragma subtitle("get_name()")
  3239. #pragma page()
  3240.  
  3241. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv get_name vvvv*/
  3242.  
  3243. /*----------------------------------------------------------------------------+
  3244. |                                                                             |
  3245. | SYNOPSIS                                                                    |
  3246. | ~~~~~~~~                                                                    |
  3247. |   #include <stdio.h>                                                        |
  3248. |   #include <string.h>                                                       |
  3249. |   void get_name (char *name_ptr, *name_for)                                 |
  3250. |                                                                             |
  3251. | FUNCTION                                                                    |
  3252. | ~~~~~~~~                                                                    |
  3253. |   Prompts the user to enter name described by *name_for, gets user          |
  3254. |   input and arranges it in the form LAST,FIRST, in upper case with          |
  3255. |   leading and trailing whitespace deleted (unless embedded within the       |
  3256. |   first or last name).                                                      |
  3257. |                                                                             |
  3258. | RETURNS                                                                     |
  3259. | ~~~~~~~                                                                     |
  3260. |   Nothing.                                                                  |
  3261. |                                                                             |
  3262. |                                                                             |
  3263. |                                                                             |
  3264. | NOTES                                                                       |
  3265. | ~~~~~                                                                       |
  3266. |   Uses macros defined in Videocat and MSC extensions.  May not be portable  |
  3267. |   accross operating systems and compilers.string functions declared         |
  3268. |                                                                             |
  3269. |                                                                             |
  3270. |                                                                             |
  3271. +----------------------------------------------------------------------------*/
  3272.  
  3273. void get_name (name_ptr, name_for)             /* func to get name from user */
  3274.  
  3275.   char                 *name_ptr;        /* place where name is to be stored */
  3276.   char                 *name_for;                    /* whose name requested */
  3277.   
  3278. {
  3279.   USHORT                cbString;                       /* string byte count */
  3280.   char                 *char_buff;                          /* string buffer */
  3281.   extern void           editLdata();   /* func to edit data to record format */
  3282.   HVIO                  hvio = 0;                            /* video handle */
  3283.   char                  input_name [INPUTLENGTH];     /* buff for user input */
  3284.   char                  name_data [INPUTLENGTH];           /* data work area */
  3285.   extern void           trim();       /* func strips lead & trail whitespace */
  3286.   extern void           window();                /* func opens screen window */
  3287.   
  3288.   char_buff = (char *) calloc (1, 0x100);
  3289.   clear_screen (LWHITE,BLACK);                  /* clear screen & set colors */
  3290.   window (0,79,0,20,LWHITE,BLUE);
  3291.   window (6,78,9,14,BLACK,BLACK);
  3292.   window (4,76,8,13,BLACK,WHITE);
  3293.   sprintf (char_buff, "Please enter requested data....");
  3294.   cbString = (USHORT)strlen(char_buff);
  3295.   VioWrtCharStr (char_buff,cbString,11,9,hvio);
  3296.   set_border (BLUE);                              /* set screen border color */
  3297.   VioSetCurPos (22,0,hvio);                               /* position cursor */
  3298.   printf (" %s LAST name -> ", name_for);       /* prompt user for last name */
  3299.   gets (input_name);                                       /* get user input */
  3300.   trim (input_name);                                           /* trim input */
  3301.   strcpy (name_data, input_name);                 /* copy input to work area */
  3302.   strcat (name_data, ",");                      /* append comma to work area */
  3303.   printf (" %s FIRST name -> ", name_for);     /* prompt user for first name */
  3304.   gets (input_name);                                       /* get user input */
  3305.   trim (input_name);                                           /* trim input */
  3306.   strcat (name_data, input_name);          /* append first name to work area */
  3307.   editLdata (name_data, NAMELENGTH);      /* edit work area to record format */
  3308.   strcpy (name_ptr, name_data);          /* copy work area to place for name */
  3309.   set_border (BLACK);
  3310.   free (char_buff);
  3311.  
  3312. }
  3313.  
  3314. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ get_name ^^^^*/
  3315.  
  3316. #pragma subtitle("get_rating()")
  3317. #pragma page()
  3318.  
  3319. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv get_rating vvvv*/
  3320.  
  3321. /*----------------------------------------------------------------------------+
  3322. |                                                                             |
  3323. | SYNOPSIS                                                                    |
  3324. | ~~~~~~~~                                                                    |
  3325. |   #include <stdio.h>                                                        |
  3326. |   #include <string.h>                                                       |
  3327. |   #include <ctype.h>                                                        |
  3328. |   void get_rating (char *rate_ptr)                                          |
  3329. |                                                                             |
  3330. | FUNCTION                                                                    |
  3331. | ~~~~~~~~                                                                    |
  3332. |   Calls function list_rates () to display rating codes and explanactions,   |
  3333. |   prompts user to enter a selected code, checks the code entered against    |
  3334. |   the codes in the global array codes[] for validity, repeats prompt if     |
  3335. |   not valid, otherwise puts character in the byte pointed to by rate_ptr.   |
  3336. | RETURNS                                                                     |
  3337. | ~~~~~~~                                                                     |
  3338. |   Nothing.                                                                  |
  3339. |                                                                             |
  3340. |                                                                             |
  3341. |                                                                             |
  3342. | NOTES                                                                       |
  3343. | ~~~~~                                                                       |
  3344. |   Accesses the global array codes[].                                        |
  3345. |                                                                             |
  3346. |                                                                             |
  3347. |                                                                             |
  3348. +----------------------------------------------------------------------------*/
  3349.  
  3350. void get_rating (rate_ptr)                /* func gets rating code from user */
  3351.  
  3352.   char                 *rate_ptr;            /* ptr to storage for subj code */
  3353.  
  3354. {
  3355.   USHORT                cbString;                       /* string byte Count */
  3356.   char                 *char_buff;                          /* string buffer */ 
  3357.   int                   count;                                    /* counter */
  3358.   HVIO                  hvio = 0;                            /* video handle */
  3359.   char                  input_rate [INPUTLENGTH];       /* user input buffer */
  3360.   extern void           trim();        /* func trims lead & trail whitespace */
  3361.   int                   valid_code = FALSE;            /* validity test flag */
  3362.   extern void           window();            /* function opens screen window */
  3363.  
  3364.   char_buff = (char *) calloc (1, 0x100);
  3365.   while (!valid_code)                      /* while valid code not entered - */
  3366.   {
  3367.    clear_screen (LWHITE,BLACK);                 /* clear screen & set colors */
  3368.    window (0,79,0,21,LWHITE,BLUE);
  3369.  
  3370.  
  3371.    window (16,39,1,6,BLUE,BLACK);
  3372.    window (15,38,0,5,BLACK,WHITE);
  3373.    VioWrtNChar ("\xDC",24,6,16,hvio);
  3374.  
  3375.    window (42,65,1,6,BLUE,BLACK);
  3376.    window (41,64,0,5,BLACK,WHITE);
  3377.    VioWrtNChar ("\xDC",24,6,42,hvio);
  3378.                                            
  3379.    set_border (BLUE);                             /* set screen border color */
  3380.    VioSetCurPos (22,0,hvio);                              /* position cursor */
  3381.  
  3382.      /* print top border of table */
  3383.  
  3384.    sprintf (char_buff,"               %c", 201);
  3385.    cbString = (USHORT)strlen(char_buff);
  3386.    VioWrtCharStr(char_buff,cbString,0,0,hvio);
  3387.    for (count = 0; count < 22; count++)
  3388.    {
  3389.       sprintf (char_buff,"%c", 205);
  3390.       cbString = (USHORT)strlen(char_buff);
  3391.       VioWrtCharStr (char_buff,cbString,0,(count + 16),hvio);
  3392.    }
  3393.    sprintf (char_buff,"%c  %c", 187, 201);
  3394.    cbString = (USHORT)strlen(char_buff);
  3395.    VioWrtCharStr(char_buff,cbString,0,38,hvio);
  3396.    for (count = 0; count < 22; count++)
  3397.    {
  3398.       sprintf (char_buff,"%c", 205);
  3399.       cbString = (USHORT)strlen(char_buff);
  3400.       VioWrtCharStr (char_buff,cbString,0,(count + 42),hvio);
  3401.    }
  3402.    sprintf (char_buff,"%c", 187);
  3403.    cbString = (USHORT)strlen(char_buff);
  3404.    VioWrtCharStr(char_buff,cbString,0,64,hvio);
  3405.  
  3406.         /* print main body of table */
  3407.  
  3408.    sprintf (char_buff,"               %c A = **** Excellent   %c",  186, 186);
  3409.    cbString = (USHORT)strlen(char_buff);
  3410.    VioWrtCharStr(char_buff,cbString,1,0,hvio);
  3411.    sprintf (char_buff,             "  %c E = **   Fair        %c",  186, 186);
  3412.    cbString = (USHORT)strlen(char_buff);  
  3413.    VioWrtCharStr(char_buff,cbString,1,39,hvio);
  3414.  
  3415.    sprintf (char_buff,"               %c B = ***+ Very Good   %c",  186, 186);
  3416.    cbString = (USHORT)strlen(char_buff);
  3417.    VioWrtCharStr(char_buff,cbString,2,0,hvio);
  3418.    sprintf (char_buff,             "  %c F = *+   Poor        %c",  186, 186);
  3419.    cbString = (USHORT)strlen(char_buff);
  3420.    VioWrtCharStr(char_buff,cbString,2,39,hvio);
  3421.  
  3422.    sprintf (char_buff,"               %c C = ***  Good        %c",  186, 186);
  3423.    cbString = (USHORT)strlen(char_buff);
  3424.    VioWrtCharStr(char_buff,cbString,3,0,hvio);
  3425.    sprintf (char_buff,             "  %c G = *    Bad         %c",  186, 186);
  3426.    cbString = (USHORT)strlen(char_buff);
  3427.    VioWrtCharStr(char_buff,cbString,3,39,hvio);
  3428.  
  3429.    sprintf (char_buff,"               %c D = **+  Pretty Good %c",  186, 186);
  3430.    cbString = (USHORT)strlen(char_buff);
  3431.    VioWrtCharStr(char_buff,cbString,4,0,hvio);
  3432.    sprintf (char_buff,             "  %c H = +    Abysmal     %c",  186, 186);
  3433.    cbString = (USHORT)strlen(char_buff);
  3434.    VioWrtCharStr(char_buff,cbString,4,39,hvio);
  3435.  
  3436.  
  3437.             /* print bottom border of table */
  3438.              
  3439.  
  3440.  
  3441.    sprintf (char_buff,"               %c", 200);
  3442.    cbString = (USHORT)strlen(char_buff);
  3443.    VioWrtCharStr(char_buff,cbString,5,0,hvio);
  3444.    for (count = 0; count < 22; count++)
  3445.    {
  3446.       sprintf (char_buff,"%c", 205);
  3447.       cbString = (USHORT)strlen(char_buff);
  3448.       VioWrtCharStr (char_buff,cbString,5,(count + 16),hvio);
  3449.    }
  3450.    sprintf (char_buff,"%c  %c", 188, 200);
  3451.    cbString = (USHORT)strlen(char_buff);
  3452.    VioWrtCharStr(char_buff,cbString,5,38,hvio);
  3453.    for (count = 0; count < 22; count++)
  3454.    {
  3455.       sprintf (char_buff,"%c", 205);
  3456.       cbString = (USHORT)strlen(char_buff);
  3457.       VioWrtCharStr (char_buff,cbString,5,(count + 42),hvio);
  3458.    }
  3459.    sprintf (char_buff,"%c", 188);
  3460.    cbString = (USHORT)strlen(char_buff);
  3461.    VioWrtCharStr(char_buff,cbString,5,64,hvio);
  3462.  
  3463.  
  3464.                    /*  get user response */
  3465.  
  3466.    VioSetCurPos (23,0,hvio);        
  3467.    printf (" Rating code -> ");                     /* prompt user for input */
  3468.    gets (input_rate);                                      /* get user input */
  3469.    trim (input_rate);                                     /* trim user input */
  3470.    *rate_ptr = toupper (input_rate[0]);      /* move first character entered */
  3471.    for (count = 0; count < RATINGNUMBER; count++)     /* compare with codes  */
  3472.      if (*rate_ptr == codes[count])             /* list; if code found, then */
  3473.               valid_code = TRUE;                            /* code is valid */
  3474.   }
  3475.   set_border (BLACK);
  3476.  
  3477.   free (char_buff);
  3478. }
  3479.  
  3480.  
  3481. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ get_rating ^^^^*/
  3482.  
  3483. #pragma subtitle("get_subject()")
  3484. #pragma page()
  3485.  
  3486. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv get_subject vvvv*/
  3487.  
  3488. /*----------------------------------------------------------------------------+
  3489. |                                                                             |
  3490. | SYNOPSIS                                                                    |
  3491. | ~~~~~~~~                                                                    |
  3492. |   #include <stdio.h>                                                        |
  3493. |   #include <string.h>                                                       |
  3494. |   #include <ctype.h>                                                        |
  3495. |   void get_subj (char *subj_ptr)                                            |
  3496. |                                                                             |
  3497. | FUNCTION                                                                    |
  3498. | ~~~~~~~~                                                                    |
  3499. |   Calls function list_subjs () to display subj codes and explanations,      |
  3500. |   prompts user to enter a selected code, checks the code entered against    |
  3501. |   the codes in the global array codes[] for validity, repeats prompt if     |
  3502. |   not valid, otherwise puts character in the byte pointed to by subj_ptr.   |
  3503. | RETURNS                                                                     |
  3504. | ~~~~~~~                                                                     |
  3505. |   Nothing.                                                                  |
  3506. |                                                                             |
  3507. |                                                                             |
  3508. |                                                                             |
  3509. | NOTES                                                                       |
  3510. | ~~~~~                                                                       |
  3511. |   Accesses the global array codes[].                                        |
  3512. |                                                                             |
  3513. |                                                                             |
  3514. |                                                                             |
  3515. |                                                                             |
  3516. |                                                                             |
  3517. +----------------------------------------------------------------------------*/
  3518.  
  3519. void get_subject (subj_ptr)                 /* func gets subj code from user */
  3520.  
  3521.   char                 *subj_ptr;            /* ptr to storage for subj code */
  3522.  
  3523. {
  3524.   USHORT                cbString;                       /* string byte Count */
  3525.   char                 *char_buff;                          /* string buffer */ 
  3526.   int                   count;                                    /* counter */
  3527.   HVIO                  hvio = 0;                            /* video handle */
  3528.   char                  input_subj [INPUTLENGTH];       /* user input buffer */
  3529.   extern void           trim();        /* func trims lead & trail whitespace */
  3530.   int                   valid_code = FALSE;            /* validity test flag */
  3531.   extern void           window();            /* function opens screen window */
  3532.  
  3533.   char_buff = (char *) calloc (1, 0x100);
  3534.   while (!valid_code)                      /* while valid code not entered - */
  3535.   {
  3536.    clear_screen (LWHITE,BLACK);                 /* clear screen & set colors */
  3537.    window (0,79,0,23,LWHITE,BLUE);
  3538.  
  3539.  
  3540.    window (16,39,1,23,BLUE,BLACK);
  3541.    window (15,38,0,22,BLACK,WHITE);
  3542.    VioWrtNChar ("\xDC",24,23,16,hvio);
  3543.  
  3544.    window (42,65,1,23,BLUE,BLACK);
  3545.    window (41,64,0,22,BLACK,WHITE);
  3546.    VioWrtNChar ("\xDC",24,23,42,hvio);
  3547.  
  3548.    set_border (BLUE);                             /* set screen border color */
  3549.    VioSetCurPos (22,0,hvio);                              /* position cursor */
  3550.  
  3551.      /* print top border of table */
  3552.  
  3553.    sprintf (char_buff,"               %c", 201);
  3554.    cbString = (USHORT)strlen(char_buff);
  3555.    VioWrtCharStr(char_buff,cbString,0,0,hvio);
  3556.    for (count = 0; count < 22; count++)
  3557.    {
  3558.       sprintf (char_buff,"%c", 205);
  3559.       cbString = (USHORT)strlen(char_buff);
  3560.       VioWrtCharStr (char_buff,cbString,0,(count + 16),hvio);
  3561.    }
  3562.    sprintf (char_buff,"%c  %c", 187, 201);
  3563.    cbString = (USHORT)strlen(char_buff);
  3564.    VioWrtCharStr(char_buff,cbString,0,38,hvio);
  3565.    for (count = 0; count < 22; count++)
  3566.    {
  3567.       sprintf (char_buff,"%c", 205);
  3568.       cbString = (USHORT)strlen(char_buff);
  3569.       VioWrtCharStr (char_buff,cbString,0,(count + 42),hvio);
  3570.    }
  3571.    sprintf (char_buff,"%c", 187);
  3572.    cbString = (USHORT)strlen(char_buff);
  3573.    VioWrtCharStr(char_buff,cbString,0,64,hvio);
  3574.  
  3575.         /* print main body of table */
  3576.  
  3577.    sprintf (char_buff,"               %c A = Action           %c",  186, 186);
  3578.    cbString = (USHORT)strlen(char_buff);
  3579.    VioWrtCharStr(char_buff,cbString,1,0,hvio);
  3580.    sprintf (char_buff,             "  %c V = Musical          %c",  186, 186);
  3581.    cbString = (USHORT)strlen(char_buff);
  3582.    VioWrtCharStr(char_buff,cbString,1,39,hvio);
  3583.  
  3584.    sprintf (char_buff,"               %c B = Adult            %c",  186, 186);
  3585.    cbString = (USHORT)strlen(char_buff);
  3586.    VioWrtCharStr(char_buff,cbString,2,0,hvio);
  3587.    sprintf (char_buff,             "  %c W = Period           %c",  186, 186);
  3588.    cbString = (USHORT)strlen(char_buff);
  3589.    VioWrtCharStr(char_buff,cbString,2,39,hvio);
  3590.  
  3591.    sprintf (char_buff,"               %c C = Animated         %c",  186, 186);
  3592.    cbString = (USHORT)strlen(char_buff);
  3593.    VioWrtCharStr(char_buff,cbString,3,0,hvio);
  3594.    sprintf (char_buff,             "  %c X = Police           %c",  186, 186);
  3595.    cbString = (USHORT)strlen(char_buff);
  3596.    VioWrtCharStr(char_buff,cbString,3,39,hvio);
  3597.  
  3598.    sprintf (char_buff,"               %c D = Biographical     %c",  186, 186);
  3599.    cbString = (USHORT)strlen(char_buff);
  3600.    VioWrtCharStr(char_buff,cbString,4,0,hvio);
  3601.    sprintf (char_buff,             "  %c Y = Political        %c",  186, 186);
  3602.    cbString = (USHORT)strlen(char_buff);
  3603.    VioWrtCharStr(char_buff,cbString,4,39,hvio);
  3604.  
  3605.    sprintf (char_buff,"               %c E = Caper            %c",  186, 186);
  3606.    cbString = (USHORT)strlen(char_buff);
  3607.    VioWrtCharStr(char_buff,cbString,5,0,hvio);
  3608.    sprintf (char_buff,             "  %c Z = Prison           %c",  186, 186);
  3609.    cbString = (USHORT)strlen(char_buff);
  3610.    VioWrtCharStr(char_buff,cbString,5,39,hvio);
  3611.  
  3612.    sprintf (char_buff,"               %c F = Contemporary     %c",  186, 186);
  3613.    cbString = (USHORT)strlen(char_buff);
  3614.    VioWrtCharStr(char_buff,cbString,6,0,hvio);
  3615.    sprintf (char_buff,             "  %c 1 = Psychological    %c",  186, 186);
  3616.    cbString = (USHORT)strlen(char_buff);
  3617.    VioWrtCharStr(char_buff,cbString,6,39,hvio);
  3618.  
  3619.    sprintf (char_buff,"               %c G = Courtroom        %c",  186, 186);
  3620.    cbString = (USHORT)strlen(char_buff);
  3621.    VioWrtCharStr(char_buff,cbString,7,0,hvio);
  3622.    sprintf (char_buff,             "  %c 2 = Religious        %c",  186, 186);
  3623.    cbString = (USHORT)strlen(char_buff);
  3624.    VioWrtCharStr(char_buff,cbString,7,39,hvio);
  3625.  
  3626.    sprintf (char_buff,"               %c H = Crime            %c",  186, 186);
  3627.    cbString = (USHORT)strlen(char_buff);
  3628.    VioWrtCharStr(char_buff,cbString,8,0,hvio);
  3629.    sprintf (char_buff,             "  %c 3 = Rock             %c",  186, 186);
  3630.    cbString = (USHORT)strlen(char_buff);
  3631.    VioWrtCharStr(char_buff,cbString,8,39,hvio);
  3632.  
  3633.  
  3634.    sprintf (char_buff,"               %c I = Dance            %c",  186, 186);
  3635.    cbString = (USHORT)strlen(char_buff);
  3636.    VioWrtCharStr(char_buff,cbString, 9,0,hvio);
  3637.    sprintf (char_buff,             "  %c 4 = Romantic         %c",  186, 186);
  3638.    cbString = (USHORT)strlen(char_buff);
  3639.    VioWrtCharStr(char_buff,cbString, 9,39,hvio);
  3640.  
  3641.    sprintf (char_buff,"               %c J = Detective        %c",  186, 186);
  3642.    cbString = (USHORT)strlen(char_buff);
  3643.    VioWrtCharStr(char_buff,cbString,10,0,hvio);
  3644.    sprintf (char_buff,             "  %c 5 = Science          %c",  186, 186);
  3645.    cbString = (USHORT)strlen(char_buff);
  3646.    VioWrtCharStr(char_buff,cbString,10,39,hvio);
  3647.  
  3648.    sprintf (char_buff,"               %c K = Disaster         %c",  186, 186);
  3649.    cbString = (USHORT)strlen(char_buff);
  3650.    VioWrtCharStr(char_buff,cbString,11,0,hvio);
  3651.    sprintf (char_buff,             "  %c 6 = Science-Fiction  %c",  186, 186);
  3652.    cbString = (USHORT)strlen(char_buff);
  3653.    VioWrtCharStr(char_buff,cbString,11,39,hvio);
  3654.  
  3655.    sprintf (char_buff,"               %c L = Family           %c",  186, 186);
  3656.    cbString = (USHORT)strlen(char_buff);
  3657.    VioWrtCharStr(char_buff,cbString,12,0,hvio);
  3658.    sprintf (char_buff,             "  %c 7 = Sex              %c",  186, 186);
  3659.    cbString = (USHORT)strlen(char_buff);
  3660.    VioWrtCharStr(char_buff,cbString,12,39,hvio);
  3661.  
  3662.    sprintf (char_buff,"               %c M = Futuristic       %c",  186, 186);
  3663.    cbString = (USHORT)strlen(char_buff);
  3664.    VioWrtCharStr(char_buff,cbString,13,0,hvio);
  3665.    sprintf (char_buff,             "  %c 8 = Social           %c",  186, 186);
  3666.    cbString = (USHORT)strlen(char_buff);
  3667.    VioWrtCharStr(char_buff,cbString,13,39,hvio);
  3668.  
  3669.    sprintf (char_buff,"               %c N = Gangster         %c",  186, 186);
  3670.    cbString = (USHORT)strlen(char_buff);
  3671.    VioWrtCharStr(char_buff,cbString,14,0,hvio);
  3672.    sprintf (char_buff,             "  %c 9 = Sports           %c",  186, 186);
  3673.    cbString = (USHORT)strlen(char_buff);
  3674.    VioWrtCharStr(char_buff,cbString,14,39,hvio);
  3675.  
  3676.    sprintf (char_buff,"               %c O = Historical       %c",  186, 186);
  3677.    cbString = (USHORT)strlen(char_buff);
  3678.    VioWrtCharStr(char_buff,cbString,15,0,hvio);
  3679.    sprintf (char_buff,             "  %c 0 = Supernatural     %c",  186, 186);
  3680.    cbString = (USHORT)strlen(char_buff);
  3681.    VioWrtCharStr(char_buff,cbString,15,39,hvio);
  3682.  
  3683.    sprintf (char_buff,"               %c P = Horror           %c",  186, 186);
  3684.    cbString = (USHORT)strlen(char_buff);
  3685.    VioWrtCharStr(char_buff,cbString,16,0,hvio);
  3686.    sprintf (char_buff,             "  %c # = Suspense         %c",  186, 186);
  3687.    cbString = (USHORT)strlen(char_buff);
  3688.    VioWrtCharStr(char_buff,cbString,16,39,hvio);
  3689.  
  3690.    sprintf (char_buff,"               %c Q = International    %c",  186, 186);
  3691.    cbString = (USHORT)strlen(char_buff);
  3692.    VioWrtCharStr(char_buff,cbString,17,0,hvio);
  3693.    sprintf (char_buff,             "  %c $ = Terror           %c",  186, 186);
  3694.    cbString = (USHORT)strlen(char_buff);
  3695.    VioWrtCharStr(char_buff,cbString,17,39,hvio);
  3696.  
  3697.    sprintf (char_buff,"               %c R = Journalism       %c",  186, 186);
  3698.    cbString = (USHORT)strlen(char_buff);
  3699.    VioWrtCharStr(char_buff,cbString,18,0,hvio);
  3700.    sprintf (char_buff,             "  %c %% = War              %c", 186, 186);
  3701.    cbString = (USHORT)strlen(char_buff);
  3702.    VioWrtCharStr(char_buff,cbString,18,39,hvio);
  3703.  
  3704.    sprintf (char_buff,"               %c S = Military         %c",  186, 186);
  3705.    cbString = (USHORT)strlen(char_buff);
  3706.    VioWrtCharStr(char_buff,cbString,19,0,hvio);
  3707.    sprintf (char_buff,             "  %c & = Western          %c",  186, 186);
  3708.    cbString = (USHORT)strlen(char_buff);
  3709.    VioWrtCharStr(char_buff,cbString,19,39,hvio);
  3710.  
  3711.    sprintf (char_buff,"               %c T = Medical          %c",  186, 186);
  3712.    cbString = (USHORT)strlen(char_buff);
  3713.    VioWrtCharStr(char_buff,cbString,20,0,hvio);
  3714.    sprintf (char_buff,             "  %c ! = Youth            %c",  186, 186);
  3715.    cbString = (USHORT)strlen(char_buff);
  3716.    VioWrtCharStr(char_buff,cbString,20,39,hvio);
  3717.  
  3718.    sprintf (char_buff,"               %c U = Murder           %c",  186, 186);
  3719.    cbString = (USHORT)strlen(char_buff);
  3720.    VioWrtCharStr(char_buff,cbString,21,0,hvio);
  3721.    sprintf (char_buff,             "  %c * = Miscellaneous    %c",  186, 186);
  3722.    cbString = (USHORT)strlen(char_buff);
  3723.    VioWrtCharStr(char_buff,cbString,21,39,hvio);
  3724.  
  3725.             /* print bottom border of table */
  3726.              
  3727.    sprintf (char_buff,"               %c", 200);
  3728.    cbString = (USHORT)strlen(char_buff);
  3729.    VioWrtCharStr(char_buff,cbString,22,0,hvio);
  3730.    for (count = 0; count < 22; count++)
  3731.    {
  3732.       sprintf (char_buff,"%c", 205);
  3733.       cbString = (USHORT)strlen(char_buff);
  3734.       VioWrtCharStr (char_buff,cbString,22,(count + 16),hvio);
  3735.    }
  3736.    sprintf (char_buff,"%c  %c", 188, 200);
  3737.    cbString = (USHORT)strlen(char_buff);
  3738.    VioWrtCharStr(char_buff,cbString,22,38,hvio);
  3739.    for (count = 0; count < 22; count++)
  3740.    {
  3741.       sprintf (char_buff,"%c", 205);
  3742.       cbString = (USHORT)strlen(char_buff);
  3743.       VioWrtCharStr (char_buff,cbString,22,(count + 42),hvio);
  3744.    }
  3745.    sprintf (char_buff,"%c", 188);
  3746.    cbString = (USHORT)strlen(char_buff);
  3747.    VioWrtCharStr(char_buff,cbString,22,64,hvio);
  3748.  
  3749.  
  3750.                    /*  get user response */
  3751.  
  3752.    VioSetCurPos (24,0,hvio);
  3753.    printf (" Subject code -> ");                    /* prompt user for input */
  3754.    gets (input_subj);                                      /* get user input */
  3755.    trim (input_subj);                                     /* trim user input */
  3756.    *subj_ptr = toupper (input_subj[0]);      /* move first character entered */
  3757.    for (count = 0; count < SUBJNUMBER; count++)       /* compare with codes  */
  3758.    if (*subj_ptr == codes[count])               /* list; if code found, then */
  3759.       valid_code = TRUE;                                    /* code is valid */
  3760.   }
  3761.   set_border (BLACK);
  3762.   free (char_buff);
  3763.  
  3764. }
  3765.  
  3766. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ get_subject ^^^^*/
  3767.  
  3768. #pragma subtitle("get_title()")
  3769. #pragma page()
  3770.  
  3771. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv get_title vvvv*/
  3772.  
  3773. /*----------------------------------------------------------------------------+
  3774. |                                                                             |
  3775. | SYNOPSIS                                                                    |
  3776. | ~~~~~~~~                                                                    |
  3777. |   #include <stdio.h>                                                        |
  3778. |   #include <string.h>                                                       |
  3779. |   void get_title (char *title_ptr)                                          |
  3780. |                                                                             |
  3781. | FUNCTION                                                                    |
  3782. | ~~~~~~~~                                                                    |
  3783. |   Prompts the user to enter title; gets user input, edits to record         |
  3784. |   format, and copies to title_ptr.                                          |
  3785. |                                                                             |
  3786. | RETURNS                                                                     |
  3787. | ~~~~~~~                                                                     |
  3788. |   Nothing.                                                                  |
  3789. |                                                                             |
  3790. |                                                                             |
  3791. | NOTES                                                                       |
  3792. | ~~~~~                                                                       |
  3793. |   Uses macros defined in Videocat and MSC extensions.  May not be portable  |
  3794. |   accross operating systems and compilers. String functions declared        |
  3795. |   in string.h.                                                              |
  3796. |                                                                             |
  3797. |                                                                             |
  3798. |                                                                             |
  3799. +----------------------------------------------------------------------------*/
  3800.  
  3801. void get_title (title_ptr)
  3802.  
  3803.   char             *title_ptr;                 /* ptr to place to store year */
  3804.  
  3805. {
  3806.   USHORT            cbString;                           /* string byte count */
  3807.   char             *char_buff;                              /* string buffer */
  3808.   extern void       editLdata();       /* func to edit data to record format */
  3809.   HVIO              hvio = 0;                                /* video handle */
  3810.   char              input_title [INPUTLENGTH];        /* title input by user */
  3811.   extern void       window();                    /* func opens screen window */
  3812.  
  3813.   char_buff = (char *) calloc (1, 0x100);
  3814.   clear_screen (LWHITE,BLACK);                  /* clear screen & set colors */
  3815.   window (0,79,0,20,LWHITE,BLUE);
  3816.   window (6,78,9,14,BLACK,BLACK);
  3817.   window (4,76,8,13,BLACK,WHITE);
  3818.   sprintf (char_buff, "Please enter requested data....");
  3819.   cbString = (USHORT)strlen(char_buff);
  3820.   VioWrtCharStr (char_buff,cbString,11,9,hvio);
  3821.   set_border (BLUE);                              /* set screen border color */
  3822.   VioSetCurPos (22,0,hvio);                               /* position cursor */
  3823.   printf (" Title -> ");                       /* prompt user to enter title */
  3824.   gets (input_title);                                      /* get user input */
  3825.   editLdata (input_title, TITLELENGTH);                   /* edit user input */
  3826.   strcpy (title_ptr, input_title);              /* copy title to destination */
  3827.   set_border (BLACK);
  3828.   free (char_buff);
  3829.  
  3830. }
  3831.  
  3832. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ get_title ^^^^*/
  3833.  
  3834. #pragma subtitle("get_year()")
  3835. #pragma page()
  3836.  
  3837. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv get_year vvvv*/
  3838.  
  3839. /*----------------------------------------------------------------------------+
  3840. |                                                                             |
  3841. | SYNOPSIS                                                                    |
  3842. | ~~~~~~~~                                                                    |
  3843. |   #include <stdio.h>                                                        |
  3844. |   #include <string.h>                                                       |
  3845. |   void get_year (char *year_ptr)                                            |
  3846. |                                                                             |
  3847. | FUNCTION                                                                    |
  3848. | ~~~~~~~~                                                                    |
  3849. |   Prompts the user to enter year; gets user input, edits to record          |
  3850. |   format, and copies to year_ptr.                                           |
  3851. |                                                                             |
  3852. | RETURNS                                                                     |
  3853. | ~~~~~~~                                                                     |
  3854. |   Nothing.                                                                  |
  3855. |                                                                             |
  3856. |                                                                             |
  3857. | NOTES                                                                       |
  3858. | ~~~~~                                                                       |
  3859. |   Uses macros defined in Videocat and MSC extensions.  May not be portable  |
  3860. |   accross operating systems and compilers.  Uses string functions declared  |
  3861. |   in string.h.                                                              |
  3862. |                                                                             |
  3863. |                                                                             |
  3864. |                                                                             |
  3865. +----------------------------------------------------------------------------*/
  3866.  
  3867. void get_year (year_ptr)
  3868.  
  3869.   char             *year_ptr;                        /* destination for year */
  3870.  
  3871. {
  3872.  
  3873.   USHORT            cbString;                           /* string byte count */
  3874.   char             *char_buff;                              /* string buffer */                            
  3875.   extern void       editRdata();      /* func to edit input to record format */
  3876.   HVIO              hvio = 0;                                /* video handle */
  3877.   char              input_year [INPUTLENGTH];             /* user year input */
  3878.   extern void       window();                    /* func opens screen window */
  3879.  
  3880.   char_buff = (char *) calloc (1, 0x100);
  3881.   clear_screen (LWHITE,BLACK);                  /* clear screen & set colors */
  3882.   window (0,79,0,20,LWHITE,BLUE);
  3883.   window (6,78,9,14,BLACK,BLACK);
  3884.   window (4,76,8,13,BLACK,WHITE);
  3885.   sprintf (char_buff, "Please enter requested data....");
  3886.   cbString = (USHORT)strlen(char_buff);
  3887.   VioWrtCharStr (char_buff,cbString,11,9,hvio);
  3888.   set_border (BLUE);                              /* set screen border color */
  3889.   VioSetCurPos (22,0,hvio);                               /* position cursor */
  3890.   printf (" Year -> ");                         /* prompt user to enter year */
  3891.   gets (input_year);                                       /* get user input */
  3892.   editRdata (input_year, YEARLENGTH);         /* edit input to record format */
  3893.   strcpy (year_ptr, input_year);                 /* copy year to destination */
  3894.   set_border (BLACK);
  3895.   free (char_buff);
  3896.  
  3897. }
  3898.  
  3899. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ get_year ^^^^*/
  3900.  
  3901. #pragma subtitle("has_color()")
  3902. #pragma page()
  3903.  
  3904. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv has_color vvvv*/
  3905.  
  3906. /*----------------------------------------------------------------------------+
  3907. |                                                                             |
  3908. | SYNOPSIS                                                                    |
  3909. | ~~~~~~~~                                                                    |
  3910. |   #include <stdio.h>                                                        |
  3911. |   #include <dos.h>                                                          |
  3912. |   int has_color()                                                           |
  3913. |                                                                             |
  3914. | FUNCTION                                                                    |
  3915. | ~~~~~~~~                                                                    |
  3916. |   Determine if the host unit is configured to display colors on the         |
  3917. |   video output.                                                             |
  3918. |                                                                             |
  3919. |                                                                             |
  3920. | RETURNS                                                                     |
  3921. | ~~~~~~~                                                                     |
  3922. |   1 if the host is configured for color display, 0 if not.                  |
  3923. |                                                                             |
  3924. |                                                                             |
  3925. |                                                                             |
  3926. | NOTES                                                                       |
  3927. | ~~~~~                                                                       |
  3928. |   Used to test for color capability before changing video attributes.       |
  3929. |   Uses VioGetConfig, an MSC extension which may not be portable accross     |
  3930. |   operating systems and compilers.                                          |
  3931. |                                                                             |
  3932. +----------------------------------------------------------------------------*/
  3933.  
  3934. int has_color()                 /* func determines if host has color display */
  3935.  
  3936. {
  3937.   VIOCONFIGINFO    vioinConfig;
  3938.   USHORT        usReserved = 0;
  3939.   HVIO            hvio;
  3940.                     
  3941. #ifndef NOCOLOR
  3942.  
  3943.   VioGetConfig (usReserved, &vioinConfig, hvio);
  3944.   if (vioinConfig.display == 0)
  3945.     return 0;
  3946.   else return 1;
  3947.  
  3948. #endif
  3949.  
  3950. #ifdef NOCOLOR  /* macro for testing monochome mode on color display */
  3951.  
  3952.   return 0;
  3953.  
  3954. #endif
  3955. }
  3956.  
  3957. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ has_color ^^^^*/
  3958.  
  3959. #pragma subtitle("in_order()")
  3960. #pragma page()
  3961.  
  3962. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv in_order vvvv*/
  3963.  
  3964. /*----------------------------------------------------------------------------+
  3965. |                                                                             |
  3966. | SYNOPSIS                                                                    |
  3967. | ~~~~~~~~                                                                    |
  3968. |   #include <stdio.h>                                                        |
  3969. |   int in_order (FILE *workf_ptr, FILE *basef_ptr,                           |
  3970. |                 struct MOVIETRANS *tree_ptr,                                |
  3971. |                 struct MOVIETRANS *base_buff, int count)                    |
  3972. |                                                                             |
  3973. |                                                                             |
  3974. | FUNCTION                                                                    |
  3975. | ~~~~~~~~                                                                    |
  3976. |   Recursive function performs in order traversal of binary tree of          |
  3977. |   transactions, compares each transaction to the next record in the         |
  3978. |   old base file, and writes new records to the work file as appropriate.    |
  3979. |                                                                             |
  3980. | RETURNS                                                                     |
  3981. | ~~~~~~~                                                                     |
  3982. |   Updated number of records processed if successful, FALSE if no            |
  3983. |   records processed.                                                        |
  3984. |                                                                             |
  3985. |                                                                             |
  3986. | NOTES                                                                       |
  3987. | ~~~~~                                                                       |
  3988. |                                                                             |
  3989. |   Uses MSC extensions and may not be portable.                              |
  3990. |                                                                             |
  3991. |                                                                             |
  3992. |                                                                             |
  3993. |                                                                             |
  3994. +----------------------------------------------------------------------------*/
  3995.  
  3996.  
  3997. int in_order (workf_ptr, basef_ptr, tree_ptr, base_buff, count)
  3998.  
  3999.   struct MOVIETRANS     *base_buff;                    /* transaction buffer */
  4000.   FILE                  *basef_ptr;                      /* ptr to base file */
  4001.   int                    count;                                  /*  counter */
  4002.   struct MOVIETRANS     *tree_ptr;     /* ptr to binary tree of adds/deletes */
  4003.   FILE                  *workf_ptr;                      /* ptr to work file */
  4004. {
  4005.  
  4006.   USHORT                 cbString;                      /* string byte count */
  4007.   char                  *char_buff;                         /* string buffer */
  4008.   HVIO                   hvio = 0;                           /* video handle */
  4009.   extern char            pause();                     /* func waits for user */
  4010.   struct MOVIERECORD    *rec_ptr;                  /* pointer to data record */
  4011.   extern int             trans_comp();         /* func compares transactions */
  4012.  
  4013.   char_buff = (char *) calloc (1, 0x100);
  4014.  
  4015.   if (tree_ptr != NULL)          /* if pointer to tree is not a null pointer */
  4016.   {
  4017.         /* recursive call to process left subtree of transactions */
  4018.  
  4019.     if (!(count = in_order (workf_ptr, basef_ptr, tree_ptr->ltransnode,
  4020.                                               base_buff, count)))
  4021.       return FALSE;      /* if left subtree not sucessfully processed, abort */
  4022.  
  4023.         /* process a node in the tree */
  4024.     {
  4025.       if ((tree_ptr->transaction == 'A') || (tree_ptr->transaction == 'D')) 
  4026.       {                                /* if transaction is an add or delete */
  4027.  
  4028.            /* if base buffer is empty, read a record from the base file */
  4029.   
  4030.         if (base_buff->transaction == '\0')       /* if base buffer is empty */
  4031.         {                                /* read a record from the base file */
  4032.           if ((fread ((char *)&base_buff->moviedata, 
  4033.                 sizeof (struct MOVIERECORD),
  4034.                  1, basef_ptr)) != 1)           /* if read is unsuccessful - */
  4035.           {
  4036.             if (feof (basef_ptr))       /* - and if eof (normal condition) - */
  4037.               base_buff->transaction = 'E';    /* - code base buffer for EOF */
  4038.             else                     /* otherwise read failure is abnormal - */
  4039.             {
  4040.               fcloseall();                              /* - close all files */
  4041.               printf ("\n Error in reading base file.\n");    /* - warn user */
  4042.               pause();                                    /* - wait for user */
  4043.               return FALSE;                                       /* - abort */
  4044.             }
  4045.           }
  4046.           else
  4047.           {
  4048.              base_buff->transaction = 'B';  /* otherwise code for base rec */
  4049.              sprintf (char_buff, "%4d ", count++);
  4050.              cbString = (USHORT)strlen(char_buff);
  4051.              VioWrtCharStr (char_buff,cbString,11,50,hvio);
  4052.           }
  4053.         }
  4054.         
  4055.   
  4056.            /* if base buffer has base record, write to workfile from  */
  4057.            /* base buffer or from current node, whichever is lower */
  4058.              
  4059.         if (base_buff->transaction == 'B') /* if base buff has base rec code */
  4060.         {
  4061.           while  (((trans_comp  (base_buff, tree_ptr))  <  0)  /* while base */
  4062.                   && (base_buff->transaction == 'B'))   /* record is lower - */
  4063.           {                                 /* write base record to workfile */
  4064.             if ((fwrite ((char *)&base_buff->moviedata,
  4065.                  sizeof (struct MOVIERECORD),
  4066.                  1, workf_ptr)) != 1)               /* if write unsuccessful */
  4067.             {     
  4068.               fcloseall();                                /* close all files */
  4069.               printf ("\n Error in writing to work file.\n");   /* warn user */
  4070.               pause();                                      /* wait for user */
  4071.               return FALSE;                                         /* abort */
  4072.             }                 /* read a new base record into the base buffer */
  4073.             if ((fread ((char *)&base_buff->moviedata,
  4074.                sizeof (struct MOVIERECORD),
  4075.                  1, basef_ptr)) != 1)              /* if read unsuccessful - */
  4076.             {
  4077.               if (feof (basef_ptr))         /* and if EOF (normal condition) */
  4078.                 base_buff->transaction = 'E';    /* code base buffer for EOF */
  4079.               else                     /* otherwise read error is abnormal - */
  4080.               {
  4081.                 fcloseall();                              /* close all files */
  4082.                 printf ("\n Error in reading base file.\n");    /* warn user */
  4083.                 pause();                                    /* wait for user */
  4084.                 return FALSE;                                       /* abort */
  4085.               }
  4086.             }                    /* otherwise code base buff for base record */
  4087.             else
  4088.             {
  4089.               base_buff->transaction = 'B';  /* otherwise code for base rec */
  4090.               sprintf (char_buff, "%4d ", count++);
  4091.               cbString = (USHORT)strlen(char_buff);
  4092.               VioWrtCharStr (char_buff,cbString,11,50,hvio);
  4093.             }
  4094.           }
  4095.           if (((trans_comp  (base_buff, tree_ptr))  >  0)  /* if base record */
  4096.                 && (base_buff->transaction == 'B'))/* greater than node trans*/
  4097.           {
  4098.             if (tree_ptr->transaction == 'D') /* if the node trans is delete */
  4099.             {
  4100.               rec_ptr = &tree_ptr->moviedata;             /* set rec pointer */
  4101.               printf ("\n Cannot delete %s - existing record not found.\n",
  4102.                        rec_ptr->title);                /* warn user no match */
  4103.             }
  4104.             if (tree_ptr->transaction == 'A')    /* if the node trans is add */
  4105.               if ((fwrite ((char *)&tree_ptr->moviedata,
  4106.                  sizeof (struct MOVIERECORD),
  4107.                  1, workf_ptr)) != 1)   /* write the node trans to work file */
  4108.               {                                     /* if write unsuccessful */
  4109.                 fcloseall();                              /* close all files */
  4110.                 printf ("\n Error in writing to work file.\n"); /* warn user */
  4111.                 pause();                                    /* wait for user */
  4112.                 return FALSE;                                       /* abort */
  4113.               }
  4114.           }     
  4115.  
  4116.               /* if node trans equals base rec and is a delete, */
  4117.               /* discard the base rec and write nothing to the work file */
  4118.               /* if node trans is an add, save the base rec */
  4119.               
  4120.           if (((trans_comp  (base_buff, tree_ptr))  ==  0)  /* if base rec = */
  4121.                 && (base_buff->transaction == 'B'))      /* current node rec */
  4122.           {
  4123.             if (tree_ptr->transaction == 'D')     /* if node rec is a delete */
  4124.               base_buff->transaction = '\0';           /* trash the base rec */
  4125.             else  /* otherwise add duplicates existing record, don't process */
  4126.             {                                    /* warn user of duplication */
  4127.               rec_ptr = &tree_ptr->moviedata;      /* set up ptr to data rec */
  4128.               printf ("\n Cannot add %s - duplicates existing record\n",
  4129.                        rec_ptr->title);
  4130.               if ((fwrite ((char *)&base_buff->moviedata,
  4131.                   sizeof (struct MOVIERECORD),
  4132.                  1, workf_ptr)) != 1)          /* write base rec to workfile */
  4133.               {                                   /* if write unsuccessful - */
  4134.                 fcloseall();                              /* close all files */
  4135.                 printf ("\n Error in writing to work file.\n"); /* warn user */
  4136.                 pause();                                    /* wait for user */
  4137.                 return FALSE;                                       /* abort */
  4138.               }                                     /* if write successful - */
  4139.               base_buff->transaction = '\0';         /* code base buff empty */
  4140.             }
  4141.           }
  4142.         }
  4143.             /* if base file EOF condition, write add trans to workfile */  
  4144.           
  4145.         if ((base_buff->transaction == 'E')        /* if base buff coded EOF */
  4146.             && (tree_ptr->transaction == 'A')) /* and current node coded add */
  4147.         {                    /* write to the work file from the current node */
  4148.           if ((fwrite ((char *)&tree_ptr->moviedata,
  4149.              sizeof (struct MOVIERECORD),
  4150.              1, workf_ptr)) != 1)                 /* if write unsuccessful - */
  4151.           {     
  4152.             fcloseall();                                  /* close all files */
  4153.             printf ("\n Error in writing to work file.\n");     /* warn user */
  4154.             pause();                                        /* wait for user */
  4155.             return FALSE;                                           /* abort */
  4156.           }
  4157.         }
  4158.         if ((base_buff->transaction == 'E')        /* if base buff coded EOF */
  4159.             && (tree_ptr->transaction == 'D')) /* and current node coded del */
  4160.         {
  4161.           rec_ptr = &tree_ptr->moviedata;          /* set up ptr to data rec */
  4162.           printf ("\n Cannot delete %s - existing record not found.\n",
  4163.                        rec_ptr->title);
  4164.         }
  4165.       }
  4166.     }
  4167.  
  4168.         /* recursive call to process right subtree of transactions */
  4169.  
  4170.  
  4171.     if (!(count = in_order (workf_ptr, basef_ptr, tree_ptr->rtransnode,
  4172.                             base_buff, count)))
  4173.     {
  4174.       DosFreeSeg (tree_ptr->sel);
  4175.       return FALSE; /* if left subtree not sucessfully processed, abort */
  4176.     }
  4177.     else
  4178.       DosFreeSeg (tree_ptr->sel);
  4179.  
  4180.   }   
  4181.   free (char_buff);
  4182.   return count;                                           /* successful exit */
  4183.  
  4184. }
  4185. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in_order ^^^^*/
  4186.  
  4187. #pragma subtitle("lbl_hp_box()")
  4188. #pragma page()
  4189.  
  4190. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv lbl_hp_box vvvv*/
  4191. /*----------------------------------------------------------------------------+
  4192. |                                                                             |
  4193. | SYNOPSIS                                                                    |
  4194. | ~~~~~~~~                                                                    |
  4195. |   #include <stdio.h>                                                        |
  4196. |   void lbl_hp_box (FILE *print_pointer, int start_row, int start_column)    |
  4197. |                                                                             |
  4198. | FUNCTION                                                                    |
  4199. | ~~~~~~~~                                                                    |
  4200. |   Sends command to printer stream in Hewlett Packard Printer Control        |
  4201. |   language to print a label box starting at start_row and start_column.     |
  4202. |                                                                             |
  4203. | RETURNS                                                                     |
  4204. | ~~~~~~~                                                                     |
  4205. |   Nothing.                                                                  |
  4206. |                                                                             |
  4207. | NOTES                                                                       |
  4208. | ~~~~~                                                                       |
  4209. |   Compatible only with HP Laserjet II and other printers which recognize    |
  4210. |   Hewlett Packard Printer Control Language.                                 |
  4211. |                                                                             |
  4212. |                                                                             |
  4213. +----------------------------------------------------------------------------*/
  4214.  
  4215.  
  4216. void lbl_hp_box (print_pointer, start_row, start_column)
  4217.   FILE *print_pointer;
  4218.   int start_row;
  4219.   int start_column;
  4220. {
  4221.   int row;
  4222.   int column;
  4223.   int count;
  4224.   row = start_row;
  4225.   column = start_column;
  4226.   lbl_hp_set_cursor (print_pointer, row, column);
  4227.   fprintf (print_pointer, "\x0C9");
  4228.   for (count = 0; count < 4; count++)
  4229.     fprintf (print_pointer, "\x0CD");
  4230.   fprintf (print_pointer, "\x0CD");
  4231.   for (count = 0; count < 40; count++)
  4232.     fprintf (print_pointer, "\x0CD");
  4233.   fprintf (print_pointer, "\x0CB");
  4234.   for (count = 0; count < 4; count++)
  4235.     fprintf (print_pointer, "\x0CD");
  4236.   fprintf (print_pointer, "\x0D1");
  4237.   for (count = 0; count < 40; count++)
  4238.     fprintf (print_pointer, "\x0CD");
  4239.   fprintf (print_pointer, "\x0BB");
  4240.  
  4241.   row = row + 1;
  4242.   lbl_hp_set_cursor (print_pointer, row, column);
  4243.   fprintf (print_pointer, "\x0BA");
  4244.   for (count = 0; count < 4; count++)
  4245.     fprintf (print_pointer, "\x020");
  4246.   fprintf (print_pointer, "\x020");
  4247.   for (count = 0; count < 40; count++)
  4248.     fprintf (print_pointer, "\x020");
  4249.   fprintf (print_pointer, "\x0BA");
  4250.   for (count = 0; count < 4; count++)
  4251.     fprintf (print_pointer, "\x020");
  4252.   fprintf (print_pointer, "\x0B3");
  4253.   for (count = 0; count < 40; count++)
  4254.     fprintf (print_pointer, "\x020");
  4255.   fprintf (print_pointer, "\x0BA");
  4256.  
  4257.   row = row + 1;
  4258.   lbl_hp_set_cursor (print_pointer, row, column);
  4259.   fprintf (print_pointer, "\x0CC");
  4260.   for (count = 0; count < 4; count++)
  4261.     fprintf (print_pointer, "\x0CD");
  4262.   fprintf (print_pointer, "\x0D1");
  4263.   for (count = 0; count < 40; count++)
  4264.     fprintf (print_pointer, "\x0CD");
  4265.   fprintf (print_pointer, "\x0B9");
  4266.   for (count = 0; count < 4; count++)
  4267.     fprintf (print_pointer, "\x020");
  4268.   fprintf (print_pointer, "\x0B3");
  4269.   for (count = 0; count < 40; count++)
  4270.     fprintf (print_pointer, "\x020");
  4271.   fprintf (print_pointer, "\x0BA");
  4272.  
  4273.   row = row + 1;
  4274.   lbl_hp_set_cursor (print_pointer, row, column);
  4275.   fprintf (print_pointer, "\x0BA");
  4276.   for (count = 0; count < 4; count++)
  4277.     fprintf (print_pointer, "\x020");
  4278.   fprintf (print_pointer, "\x0B3");
  4279.   for (count = 0; count < 40; count++)
  4280.     fprintf (print_pointer, "\x020");
  4281.   fprintf (print_pointer, "\x0BA");
  4282.   for (count = 0; count < 4; count++)
  4283.     fprintf (print_pointer, "\x020");
  4284.   fprintf (print_pointer, "\x0B3");
  4285.   for (count = 0; count < 40; count++)
  4286.     fprintf (print_pointer, "\x020");
  4287.   fprintf (print_pointer, "\x0BA");
  4288.  
  4289.   row = row + 1;
  4290.   lbl_hp_set_cursor (print_pointer, row, column);
  4291.   fprintf (print_pointer, "\x0BA");
  4292.   for (count = 0; count < 4; count++)
  4293.     fprintf (print_pointer, "\x020");
  4294.   fprintf (print_pointer, "\x0B3");
  4295.   for (count = 0; count < 40; count++)
  4296.     fprintf (print_pointer, "\x020");
  4297.   fprintf (print_pointer, "\x0BA");
  4298.   for (count = 0; count < 4; count++)
  4299.     fprintf (print_pointer, "\x020");
  4300.   fprintf (print_pointer, "\x0B3");
  4301.   for (count = 0; count < 40; count++)
  4302.     fprintf (print_pointer, "\x020");
  4303.   fprintf (print_pointer, "\x0BA");
  4304.  
  4305.   row = row + 1;
  4306.   lbl_hp_set_cursor (print_pointer, row, column);
  4307.   fprintf (print_pointer, "\x0C8");
  4308.   for (count = 0; count < 4; count++)
  4309.     fprintf (print_pointer, "\x0CD");
  4310.   fprintf (print_pointer, "\x0CF");
  4311.   for (count = 0; count < 40; count++)
  4312.     fprintf (print_pointer, "\x0CD");
  4313.   fprintf (print_pointer, "\x0CA");
  4314.   for (count = 0; count < 4; count++)
  4315.     fprintf (print_pointer, "\x0CD");
  4316.   fprintf (print_pointer, "\x0CF");
  4317.   for (count = 0; count < 40; count++)
  4318.     fprintf (print_pointer, "\x0CD");
  4319.   fprintf (print_pointer, "\x0BC");
  4320.  
  4321. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lbl_hp_box ^^^^*/
  4322.  
  4323.  
  4324. #pragma subtitle("lbl_hp_line_printer()")
  4325. #pragma page()
  4326.  
  4327. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv lbl_hp_line_printer vvvv*/
  4328. /*----------------------------------------------------------------------------+
  4329. |                                                                             |
  4330. | SYNOPSIS                                                                    |
  4331. | ~~~~~~~~                                                                    |
  4332. |   #include <stdio.h>                                                        |
  4333. |   void lbl_hp_line_printer (FILE *print_pointer)                            |
  4334. |                                                                             |
  4335. | FUNCTION                                                                    |
  4336. | ~~~~~~~~                                                                    |
  4337. |   Sends command to printer stream in Hewlett Packard Printer Control        |
  4338. |   language to set font to portrait line printer.                            |
  4339. |                                                                             |
  4340. | RETURNS                                                                     |
  4341. | ~~~~~~~                                                                     |
  4342. |   Nothing.                                                                  |
  4343. |                                                                             |
  4344. | NOTES                                                                       |
  4345. | ~~~~~                                                                       |
  4346. |   Compatible only with HP Laserjet II and other printers which recognize    |
  4347. |   Hewlett Packard Printer Control Language.                                 |
  4348. |                                                                             |
  4349. |                                                                             |
  4350. +----------------------------------------------------------------------------*/
  4351.  
  4352.  
  4353. void lbl_hp_line_printer (print_pointer)
  4354.   FILE *print_pointer;
  4355. {
  4356.   fprintf (print_pointer,
  4357.     "\x01B&l0O"                                      /* portrait orientation */
  4358.     "\x01B(10U"                                           /* PC-8 Symbol Set */
  4359.     "\x01B(s0P"                                             /* fixed spacing */
  4360.     "\x01B(s16.6H"                                         /* 16.6 cpi pitch */
  4361.     "\x01B(s8.5V"                                        /* 8.5 point height */
  4362.     "\x01B&l8D"                                        /* 8 lpi line spacing */
  4363.     "\x01B(s0S"                                             /* upright style */
  4364.     "\x01B(s0B"                                      /* medium stroke weight */
  4365.     "\x01B(s0T");                                   /* Line Printer typeface */
  4366. }
  4367.  
  4368. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lbl_hp_line_printer ^^^^*/
  4369.  
  4370. #pragma subtitle("lbl_hp_print()")
  4371. #pragma page()
  4372.  
  4373. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv lbl_hp_print vvvv*/
  4374. /*----------------------------------------------------------------------------+
  4375. |                                                                             |
  4376. | SYNOPSIS                                                                    |
  4377. | ~~~~~~~~                                                                    |
  4378. |   #include <stdio.h>                                                        |
  4379. |   struct LABELDATA *lbl_hp_print(LABELDATA *lbltree_node,                   |
  4380. |                           FILE *print_pointer)                              |
  4381. |                                                                             |
  4382. | FUNCTION                                                                    |
  4383. | ~~~~~~~~                                                                    |
  4384. |   Prints labels from an in order search of the binary tree pointed to by    |
  4385. |   *lbltree_node through the printer stream pointed to by print_pointer.     |
  4386. |                                                                             |
  4387. | RETURNS                                                                     |
  4388. | ~~~~~~~                                                                     |
  4389. |   Returns a pointer to a record containing labeling status (loc1 for which  |
  4390. |   label is currently being printed and # of lines printed).  Return value   |
  4391. |   is used by calling module to complete current label after tree completed. |
  4392. |                                                                             |
  4393. | NOTES                                                                       |
  4394. | ~~~~~                                                                       |
  4395. |   Calls other functions which use MSC extensions and may not be portable.   |
  4396. |   Calls itself recursively until the tree is completely traversed.          |
  4397. |   Intended for HP Laserjet and compatibles only.                            |
  4398. |                                                                             |
  4399. +----------------------------------------------------------------------------*/
  4400.  
  4401. struct LABELDATA *lbl_hp_print(lbltree_node, print_pointer, run_number)
  4402.   
  4403.   struct LABELNODE         *lbltree_node;
  4404.   FILE                     *print_pointer;              
  4405.   int                       run_number;               /* number of label run */
  4406.  
  4407.  
  4408. {
  4409.  
  4410.   static char               current_loc [LOCLENGTH];         /* current loc1 */
  4411.   static int                current_run;      /* number of current label run */
  4412.   static int                label_count = 0;               /* labels printed */
  4413.   static struct LABELDATA   label_status;                    /* label status */
  4414.   static int                print_count = 0;                /* lines printed */
  4415.  
  4416.  
  4417.   if (current_run != run_number)
  4418.   {
  4419.     label_count = 0;
  4420.     print_count = 0;
  4421.     current_loc[0] = '\0';
  4422.     current_run = run_number;
  4423.   }
  4424.  
  4425.   if (lbltree_node != NULL)          /* if tree pointer is not null pointer, */
  4426.   {                                            /* process left subtree first */
  4427.     lbl_hp_print (lbltree_node->lnode, print_pointer, run_number);
  4428.                                                      /* recursive invocation */
  4429.     {
  4430.             /* if no lines have been printed on the current label      */
  4431.             /*     or                                                  */
  4432.             /* if lines have already been printed on the current label */
  4433.             /* and the current node is a new loc1 -                    */
  4434.             /*    then                                                 */
  4435.             /* prepare a new label for printing                        */
  4436.             
  4437.       if ((!(print_count))
  4438.          || ((print_count) && (strcmp (lbltree_node->loc1, current_loc))))
  4439.       {
  4440.         if (label_count > 12)                             /* if page is full */
  4441.         {
  4442.           fprintf (print_pointer, "\f");                       /* page eject */
  4443.           label_count = 0;                              /* reset label count */
  4444.         }
  4445.         label_count++;                              /* increment label count */
  4446.         print_count = 0;                               /* reset line count   */
  4447.         lbl_hp_box (print_pointer, (6 * (label_count - 1)), 0);
  4448.         lbl_hp_set_cursor (print_pointer, ((6 * (label_count - 1)) + 1), 10);
  4449.         fprintf (print_pointer, "Cassette Number: %s", lbltree_node->loc1);
  4450.         print_count++;        
  4451.       }
  4452.  
  4453.             /* in all cases - */
  4454.  
  4455.       {
  4456.         strcpy (current_loc, lbltree_node->loc1);  /* get current loc1 from  */
  4457.                                                    /* current node           */
  4458.         if (print_count < 3)                       /* if fewer than 4 lines  */
  4459.           lbl_hp_set_cursor (print_pointer,
  4460.                         ((6 * (label_count - 1)) + print_count + 2),
  4461.                          1);
  4462.         else                             
  4463.           lbl_hp_set_cursor (print_pointer,
  4464.                         ((6 * (label_count - 1)) + print_count - 2),
  4465.                          47);
  4466.         fprintf (print_pointer, "%s %s",
  4467.                                 lbltree_node->loc2,
  4468.                                 lbltree_node->title);
  4469.         print_count++;                               /* increment line count */
  4470.         if (print_count > 6)
  4471.           print_count = 0;
  4472.       }
  4473.     }
  4474.     lbl_hp_print (lbltree_node->rnode, print_pointer, run_number);
  4475.     DosFreeSeg (lbltree_node->sel);  /* done with current node - free memory */
  4476.                                                         /* right subtree next*/
  4477.   }
  4478.  
  4479.         /* record status of current label and return to calling module */
  4480.         
  4481.   *label_status.loc1 = (char *)(current_loc);     /* pointer to current loc1 */
  4482.   label_status.line_count = (int *)&print_count;  /* # of lines printed      */
  4483.   label_status.label_count = (int *)&label_count;
  4484.   return (&label_status);                         /* return values */
  4485.  
  4486. }
  4487.  
  4488. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lbl_hp_print ^^^^*/
  4489.  
  4490. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv lbl_hp_reset vvvv*/
  4491. /*----------------------------------------------------------------------------+
  4492. |                                                                             |
  4493. | SYNOPSIS                                                                    |
  4494. | ~~~~~~~~                                                                    |
  4495. |   #include <stdio.h>                                                        |
  4496. |   void lbl_hp_reset (FILE *print_pointer)                                   |
  4497. |                                                                             |
  4498. | FUNCTION                                                                    |
  4499. | ~~~~~~~~                                                                    |
  4500. |   Sends command to printer stream in Hewlett Packard Printer Control        |
  4501. |   language to reset printer to user default settings.                       |
  4502. |                                                                             |
  4503. | RETURNS                                                                     |
  4504. | ~~~~~~~                                                                     |
  4505. |   Nothing.                                                                  |
  4506. |                                                                             |
  4507. | NOTES                                                                       |
  4508. | ~~~~~                                                                       |
  4509. |   Compatible only with HP Laserjet II and other printers which recognize    |
  4510. |   Hewlett Packard Printer Control Language.                                 |
  4511. |                                                                             |
  4512. |                                                                             |
  4513. +----------------------------------------------------------------------------*/
  4514.  
  4515.  
  4516. void lbl_hp_reset (print_pointer)
  4517.   FILE *print_pointer;
  4518. {
  4519.   fprintf (print_pointer, "\x01BE");
  4520. }
  4521.  
  4522.  
  4523. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lbl_hp_reset ^^^^*/
  4524.  
  4525. #pragma subtitle("lbl_hp_set_cursor()")
  4526. #pragma page()
  4527.  
  4528. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv lbl_hp_set_cursor vvvv*/
  4529. /*----------------------------------------------------------------------------+
  4530. |                                                                             |
  4531. | SYNOPSIS                                                                    |
  4532. | ~~~~~~~~                                                                    |
  4533. |   #include <stdio.h>                                                        |
  4534. |   void lbl_hp_set_cursor (FILE * print_pointer, int row, int column)        |
  4535. |                                                                             |
  4536. | FUNCTION                                                                    |
  4537. | ~~~~~~~~                                                                    |
  4538. |   Sends command to printer stream in Hewlett Packard Printer Control        |
  4539. |   language to set printer cursor to row and column + 20 col margin.         |
  4540. |                                                                             |
  4541. | RETURNS                                                                     |
  4542. | ~~~~~~~                                                                     |
  4543. |   Nothing.                                                                  |
  4544. |                                                                             |
  4545. | NOTES                                                                       |
  4546. | ~~~~~                                                                       |
  4547. |   Compatible only with HP Laserjet II and other printers which recognize    |
  4548. |   Hewlett Packard Printer Control Language.                                 |
  4549. |                                                                             |
  4550. |                                                                             |
  4551. +----------------------------------------------------------------------------*/
  4552.  
  4553.  
  4554. void lbl_hp_set_cursor (print_pointer, row, column)
  4555.   FILE *print_pointer;
  4556.   int row;
  4557.   int column;
  4558. {
  4559.   char row_command[80];
  4560.   char column_command[80];
  4561.   char num_string[80];
  4562.  
  4563.   strcpy (row_command, "\x01B&a");
  4564.   itoa (row, num_string, 10);
  4565.   strcat (row_command, num_string);
  4566.   strcat (row_command, "R");
  4567.   fprintf (print_pointer, row_command);
  4568.  
  4569.   strcpy (column_command, "\x01B&a");
  4570.   itoa ((column + 20), num_string, 10);
  4571.   strcat (column_command, num_string);
  4572.   strcat (column_command, "C");
  4573.   fprintf (print_pointer, column_command);
  4574.  
  4575. }
  4576. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lbl_hp_set_cursor ^^^^*/
  4577.  
  4578. #pragma subtitle("lbl_loc_comp()")
  4579. #pragma page()
  4580.  
  4581. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv lbl_loc_comp vvvv*/
  4582.  
  4583. /*----------------------------------------------------------------------------+
  4584. |                                                                             |
  4585. | SYNOPSIS                                                                    |
  4586. | ~~~~~~~~                                                                    |
  4587. |   #include <stdio.h>                                                        |
  4588. |   #include <string.h>                                                       |
  4589. |   #include <videocat.h>                                                     |
  4590. |   int lbl_loc_comp  (struct LABELNODE loc_node1,                            |
  4591. |                      struct LABELNODE loc_node2)                            |
  4592. |                                                                             |
  4593. | FUNCTION                                                                    |
  4594. | ~~~~~~~~                                                                    |
  4595. |  Compares the records pointed to by loc_node1 and loc_node2, first by loc1  |
  4596. |  (in ASCII collating sequence), then by loc2 if loc1's are equal,           |
  4597. |  then by titles if both loc1 and loc2 are equal.                            |
  4598. |                                                                             |
  4599. | RETURNS                                                                     |
  4600. | ~~~~~~~                                                                     |
  4601. |   less than zero if rec1 is less than rec2                                  |
  4602. |   zero if rec1 is equal to rec2                                             |
  4603. |   greater than zero if rec1 is greater than rec2                            |
  4604. |                                                                             |
  4605. | NOTES                                                                       |
  4606. | ~~~~~                                                                       |
  4607. |   Comparison is used to sort records into location sequence.                |
  4608. |                                                                             |
  4609. +----------------------------------------------------------------------------*/
  4610.  
  4611. int lbl_loc_comp (loc_node1, loc_node2)
  4612.  
  4613. struct LABELNODE *loc_node1, *loc_node2;          /* ptrs to two label nodes */
  4614.  
  4615. {
  4616.   int comp_result;                                   /* result of comparison */
  4617.  
  4618.   comp_result = strcmp (loc_node1->loc1, loc_node2->loc1);   /* compare loc1 */
  4619.  
  4620.   if (comp_result == 0)                       /* if same, then compare loc2) */
  4621.     comp_result = strcmp (loc_node1->loc2, loc_node2->loc2);
  4622.   if (comp_result == 0)                /* if still same, then compare titles */
  4623.     comp_result = strcmp (loc_node1->title, loc_node2->title);
  4624.   return (comp_result);                       /* return result of comparison */
  4625.  
  4626. }
  4627.  
  4628. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lbl_loc_comp ^^^^*/
  4629.  
  4630. #pragma subtitle("lbl_make_labels()")
  4631. #pragma page()
  4632.  
  4633. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv lbl_make_labels vvvv*/
  4634. /*----------------------------------------------------------------------------+
  4635. |                                                                             |
  4636. | SYNOPSIS                                                                    |
  4637. | ~~~~~~~~                                                                    |
  4638. |   #include <stdio.h>                                                        |
  4639. |   void lbl_make_labels (char *base_file_id)                                 |
  4640. |                                                                             |
  4641. | FUNCTION                                                                    |
  4642. | ~~~~~~~~                                                                    |
  4643. |   Prompts user to enter range of cassetes to be labeled, calls func to get  |
  4644. |   data from base_file_id, gets printer type, calls func to print labels.    |
  4645. |                                                                             |
  4646. | RETURNS                                                                     |
  4647. | ~~~~~~~                                                                     |
  4648. |   Nothing.                                                                  |
  4649. |                                                                             |
  4650. | NOTES                                                                       |
  4651. | ~~~~~                                                                       |
  4652. |   Calls other functions which use MSC extensions and may not be portable.   |
  4653. |                                                                             |
  4654. |                                                                             |
  4655. +----------------------------------------------------------------------------*/
  4656.  
  4657.  
  4658. void lbl_make_labels (base_file_id)
  4659.   char   *base_file_id;
  4660. {
  4661.   static int    a_run_number = 0;              /* number times this func run */
  4662.   USHORT        cbString;                               /* string byte count */
  4663.   char         *char_buff;                                  /* string buffer */
  4664.   extern void   clear_screen();                      /* func to clear screen */
  4665.   int           count;                                            /* counter */
  4666.   char         *current_loc;                             /* current location */
  4667.   extern void   get_loc();                   /* func gets location from user */
  4668.   char          go_ahead = ' ';         /* quit or go ahead signal from user */
  4669.   static int    h_run_number = 0;              /* number times this func run */
  4670.   HVIO          hvio = 0;                                    /* video handle */
  4671.   struct LABELNODE           *lbltree_root = NULL;   /* root for binary tree */
  4672.   struct LABELDATA           *label_data;         /* struct holds label data */
  4673.   extern struct LABELDATA    *lbl_hp_print();  /* func prints labels on HPLJ */
  4674.   extern void   lbl_hp_line_printer();   /* func sets HPLJ line printer font */
  4675.   extern void   lbl_hp_reset(); /* func resets HPLJ to user default settings */
  4676.   extern struct LABELNODE    *lbl_search();     /* func gets data for labels */
  4677.   extern struct LABELDATA    *lbl_print(); /* func prints labels std printer */
  4678.   char          min_loc [LOCLENGTH];             /* lowest cassette to label */
  4679.   char          max_loc [LOCLENGTH];            /* highest cassette to label */
  4680.   extern char   prnopt();                          /* func gets printer type */
  4681.   char          printer_type = '\0';                /* code for printer type */
  4682.   int           print_count;                                /* print counter */
  4683.   int           print_handle;                     /* file handle for printer */
  4684.   FILE         *print_pointer;                         /* stream for printer */
  4685.   extern char   qpause();                /* func pauses for go-ahead or quit */
  4686.   extern void   set_border();              /* func sets display border color */
  4687.  
  4688.   char_buff = (char *) calloc (1, 0x100);
  4689.   clear_screen (LWHITE,BLACK);                  /* clear screen & set colors */
  4690.   window (0,79,0,20,LWHITE,BLUE);
  4691.   window (6,78,9,14,BLACK,BLACK);
  4692.   window (4,76,8,13,BLACK,WHITE);
  4693.   set_border (BLUE);                              /* set screen border color */
  4694.  
  4695.   sprintf(char_buff,
  4696.    " Enter the range of cassettes for which labels are to be printed.      ");
  4697.   cbString = (USHORT)strlen(char_buff);
  4698.   VioWrtCharStr (char_buff,cbString,9,6,hvio);
  4699.   sprintf(char_buff,
  4700.    " It is not recommended that the range specified for a single run of    ");
  4701.   cbString = (USHORT)strlen(char_buff);
  4702.   VioWrtCharStr (char_buff,cbString,10,6,hvio);
  4703.   sprintf(char_buff,
  4704.    " this function exceed 200 cassettes, so that the amount of RAM which   ");
  4705.   cbString = (USHORT)strlen(char_buff);
  4706.   VioWrtCharStr (char_buff,cbString,11,6,hvio);
  4707.   sprintf(char_buff,
  4708.    " must be allocated for sorting will not exceed available memory.       ");
  4709.   cbString = (USHORT)strlen(char_buff);
  4710.   VioWrtCharStr (char_buff,cbString,12,6,hvio);
  4711.   VioSetCurPos (22,0,hvio);                               /* position cursor */
  4712.   pause();
  4713.  
  4714.   get_loc (min_loc, "Lowest cassette to label ");      /* get cassette range */
  4715.   get_loc (max_loc, "Highest cassette to label");
  4716.  
  4717.   printer_type = prnopt();                               /* get printer type */
  4718.  
  4719.   clear_screen (LWHITE,BLACK);                  /* clear screen & set colors */
  4720.   window (0,79,0,20,LWHITE,BLUE);
  4721.   window (6,78,9,14,BLACK,BLACK);
  4722.   window (4,76,8,13,BLACK,WHITE);
  4723.   set_border (BLUE);                              /* set screen border color */
  4724.  
  4725.   sprintf(char_buff,
  4726.    " Searching for and sorting data for labels...                          ");
  4727.   cbString = (USHORT)strlen(char_buff);
  4728.   VioWrtCharStr (char_buff,cbString,10,6,hvio);
  4729.   VioSetCurPos (22,0,hvio);                               /* position cursor */
  4730.  
  4731.   lbltree_root = lbl_search (base_file_id, min_loc, max_loc);    /* get data */
  4732.  
  4733.   print_handle = open ("PRN", O_WRONLY);                 /* open file handle */
  4734.   if (print_handle == -1)                             /* test for open error */
  4735.      perror ("open failed on PRN");
  4736.   print_pointer = fdopen (print_handle, "w");            /* associate stream */
  4737.   if (print_pointer == NULL)                               /* test for error */
  4738.      perror ("fopen failed on print_handle");
  4739.  
  4740.   switch (printer_type)               /* selection according to printer type */
  4741.   {
  4742.     case 'A':                                            /* if ASCII printer */
  4743.  
  4744.      clear_screen (LWHITE,BLACK);               /* clear screen & set colors */
  4745.      window (0,79,0,20,LWHITE,BLUE);
  4746.      window (6,78,9,14,BLACK,BLACK);
  4747.      window (4,76,8,13,BLACK,WHITE);
  4748.      set_border (BLUE);                           /* set screen border color */
  4749.  
  4750.      sprintf(char_buff,
  4751.       " This routine assumes a standard printer, 10 cpi, 6 lpi, controlled ");
  4752.      cbString = (USHORT)strlen(char_buff);
  4753.      VioWrtCharStr (char_buff,cbString,9,6,hvio);
  4754.      sprintf(char_buff,
  4755.       " by ASCII commands,  continuous form 3.5 x 15/16\" labels, 1-wide,");
  4756.      cbString = (USHORT)strlen(char_buff);
  4757.      VioWrtCharStr (char_buff,cbString,10,6,hvio);
  4758.      sprintf(char_buff,
  4759.       " with first label positioned so that the first print position would ");
  4760.      cbString = (USHORT)strlen(char_buff);
  4761.      VioWrtCharStr (char_buff,cbString,11,6,hvio);
  4762.      sprintf(char_buff,
  4763.       " be just within the upper left corner of the first label.           ");
  4764.      cbString = (USHORT)strlen(char_buff);
  4765.      VioWrtCharStr (char_buff,cbString,12,6,hvio);
  4766.      VioSetCurPos (22,0,hvio);                            /* position cursor */
  4767.      go_ahead = qpause();
  4768.      if (go_ahead == 'Q')
  4769.      {
  4770.        fcloseall();
  4771.        return;
  4772.      }
  4773.  
  4774.      clear_screen (LWHITE,BLACK);               /* clear screen & set colors */
  4775.      window (0,79,0,20,LWHITE,BLUE);
  4776.      window (6,78,9,14,BLACK,BLACK);
  4777.      window (4,76,8,13,BLACK,WHITE);
  4778.      set_border (BLUE);                           /* set screen border color */
  4779.  
  4780.      sprintf(char_buff,
  4781.       " Printing labels... ");
  4782.      cbString = (USHORT)strlen(char_buff);
  4783.      VioWrtCharStr (char_buff,cbString,10,26,hvio);
  4784.      VioSetCurPos (22,0,hvio);                            /* position cursor */
  4785.  
  4786.      a_run_number++;                                 /* increment run number */
  4787.      label_data = lbl_print (lbltree_root, print_pointer, a_run_number);
  4788.      print_count = *label_data->line_count;
  4789.      current_loc = *label_data->loc1;  
  4790.      if (print_count)           /* if lines printed on last label, finish it */
  4791.      {
  4792.        for (count = print_count; count <= 4; count++)
  4793.        {
  4794.          fprintf (print_pointer, "%c\n", current_loc[count]);
  4795.          print_count++;
  4796.        }
  4797.        while (print_count < 6)
  4798.        {
  4799.          fprintf (print_pointer, "\n");
  4800.          print_count++;
  4801.        }
  4802.        print_count = 0;
  4803.      }
  4804.      break;
  4805.  
  4806.     case 'H':                                              /* if HP Laserjet */
  4807.  
  4808.      sprintf(char_buff,
  4809.       " This routine assumes a Hewlett Packard Laserjet II printer,        ");
  4810.      cbString = (USHORT)strlen(char_buff);
  4811.      VioWrtCharStr (char_buff,cbString,9,6,hvio);
  4812.      sprintf(char_buff,
  4813.       " printing on 8-1/2 x 11\" label paper, uncut, 1 label per page,     ");
  4814.      cbString = (USHORT)strlen(char_buff);
  4815.      VioWrtCharStr (char_buff,cbString,10,6,hvio);
  4816.      sprintf(char_buff,
  4817.       " (Hewlett Packard Part Number 92285W, Avery Part Number 5353,       ");
  4818.      cbString = (USHORT)strlen(char_buff);
  4819.      VioWrtCharStr (char_buff,cbString,11,6,hvio);
  4820.      sprintf(char_buff,
  4821.       " or equivalent).  Cut labels to size after printing.                ");
  4822.      cbString = (USHORT)strlen(char_buff);
  4823.      VioWrtCharStr (char_buff,cbString,12,6,hvio);
  4824.      VioSetCurPos (22,0,hvio);                            /* position cursor */
  4825.      go_ahead = qpause();
  4826.      if (go_ahead == 'Q')
  4827.      {
  4828.        fcloseall();
  4829.        return;
  4830.      }
  4831.  
  4832.      clear_screen (LWHITE,BLACK);               /* clear screen & set colors */
  4833.      window (0,79,0,20,LWHITE,BLUE);
  4834.      window (6,78,9,14,BLACK,BLACK);
  4835.      window (4,76,8,13,BLACK,WHITE);
  4836.      set_border (BLUE);                           /* set screen border color */
  4837.  
  4838.      sprintf(char_buff,
  4839.       " Printing labels... ");
  4840.      cbString = (USHORT)strlen(char_buff);
  4841.      VioWrtCharStr (char_buff,cbString,10,26,hvio);
  4842.      VioSetCurPos (22,0,hvio);                            /* position cursor */
  4843.  
  4844.      h_run_number++;                                 /* increment run number */
  4845.      lbl_hp_reset (print_pointer);
  4846.      lbl_hp_line_printer (print_pointer);
  4847.      label_data = lbl_hp_print (lbltree_root, print_pointer, h_run_number);
  4848.      lbl_hp_reset (print_pointer);
  4849.      break;
  4850.  
  4851.    default:
  4852.  
  4853.      printf (" Error in printer type code.\n");
  4854.      pause();
  4855.      return;
  4856.   }
  4857.  
  4858.   free (char_buff);
  4859.  
  4860.   if (fclose (print_pointer) == EOF)                         /* close stream */
  4861.       perror ("fclose failed on print_pointer");           /* test for error */
  4862.  
  4863. }
  4864. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lbl_make_labels ^^^^*/
  4865.  
  4866. #pragma subtitle("lbl_print()")
  4867. #pragma page()
  4868.  
  4869. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv lbl_print vvvv*/
  4870. /*----------------------------------------------------------------------------+
  4871. |                                                                             |
  4872. | SYNOPSIS                                                                    |
  4873. | ~~~~~~~~                                                                    |
  4874. |   #include <stdio.h>                                                        |
  4875. |   struct LABELDATA *lbl_print(LABELDATA *lbltree_node, FILE *print_pointer) |
  4876. |                                                                             |
  4877. | FUNCTION                                                                    |
  4878. | ~~~~~~~~                                                                    |
  4879. |   Prints labels from an in order search of the binary tree pointed to by    |
  4880. |   *lbltree_node through the printer stream pointed to by print_pointer.     |
  4881. |                                                                             |
  4882. | RETURNS                                                                     |
  4883. | ~~~~~~~                                                                     |
  4884. |   Returns a pointer to a record containing labeling status (loc1 for which  |
  4885. |   label is currently being printed and # of lines printed).  Return value   |
  4886. |   is used by calling module to complete current label after tree completed. |
  4887. |                                                                             |
  4888. | NOTES                                                                       |
  4889. | ~~~~~                                                                       |
  4890. |   Calls other functions which use MSC extensions and may not be portable.   |
  4891. |   Calls itself recursively until the tree is completely traversed.          |
  4892. |                                                                             |
  4893. |                                                                             |
  4894. +----------------------------------------------------------------------------*/
  4895.  
  4896. struct LABELDATA *lbl_print(lbltree_node, print_pointer, run_number)
  4897.  
  4898.   struct LABELNODE         *lbltree_node;           /* ptr to tree structure */
  4899.   FILE                     *print_pointer;             /* stream for printer */
  4900.   int                       run_number;               /* number of label run */
  4901. {
  4902.  
  4903.   int                       count;                                /* counter */
  4904.   static int                print_count = 0;                /* lines printed */
  4905.   static char               current_loc [LOCLENGTH];         /* current loc1 */
  4906.   static struct LABELDATA   label_status;                    /* label status */
  4907.   static int                current_run;      /* number of current label run */
  4908.  
  4909.   if (current_run != run_number)
  4910.   {
  4911.     count = 0;
  4912.     print_count = 0;
  4913.     current_loc[0] = '\0';
  4914.     current_run = run_number;
  4915.   }
  4916.   if (lbltree_node != NULL)          /* if tree pointer is not null pointer, */
  4917.   {                                            /* process left subtree first */
  4918.     lbl_print (lbltree_node->lnode, print_pointer, current_run);
  4919.                                                      /* recursive invocation */
  4920.     {
  4921.       lbltree_node->title[30] = '\0';      /* truncate title for label width */
  4922.  
  4923.          /* if lines have already been printed on the current label */
  4924.          /* and the current node is a new loc1 -                    */
  4925.  
  4926.       if ((print_count) && (strcmp (lbltree_node->loc1, current_loc)))
  4927.       {
  4928.         for (count = print_count; count <= 4; count++) /* print the rest of  */
  4929.         {                                              /* the location i.d.  */
  4930.           fprintf (print_pointer, "%c\n", current_loc[count]);
  4931.           print_count++;
  4932.         }
  4933.         while (print_count < 6)                           /* space to the begin-*/ 
  4934.         {                                              /* ning of the next   */
  4935.           fprintf (print_pointer, "\n");               /* label              */
  4936.           print_count++;
  4937.         }
  4938.         print_count = 0;                               /* reset line count   */
  4939.       }
  4940.  
  4941.             /* in all cases - */
  4942.  
  4943.       {
  4944.         strcpy (current_loc, lbltree_node->loc1);  /* get current loc1 from  */
  4945.                                                    /* current node           */
  4946.         if (print_count >= 5)                      /* if label is full,      */               
  4947.         {                                     
  4948.           fprintf (print_pointer, "\n");           /* skip to next label     */
  4949.           print_count = 0;                         /* and reset line count   */
  4950.         }
  4951.         if (print_count < 4)                       /* if fewer than 4 lines  */
  4952.         {                                          /* have been printed -    */
  4953.           fprintf (print_pointer, "%c  %s\n",      /* print the next char in */
  4954.               current_loc[print_count], lbltree_node->title); /* loc1 i.d. & */
  4955.         }                                                     /* title       */
  4956.         else                                       /* if 4 or more lines     */ 
  4957.         {                                          /* have been printed -    */
  4958.           fprintf (print_pointer, "%c  %s\n",      /* just print title       */
  4959.               ' ', lbltree_node->title);
  4960.         }
  4961.         print_count++;                               /* increment line count */
  4962.       }
  4963.     }
  4964.     lbl_print (lbltree_node->rnode, print_pointer, current_run);
  4965.     DosFreeSeg (lbltree_node->sel);  /* done with current node - free memory */
  4966.                                                         /* right subtree next*/
  4967.   }
  4968.  
  4969.         /* record status of current label and return to calling module */
  4970.         
  4971.   *label_status.loc1 = (char *)(current_loc);     /* pointer to current loc1 */
  4972.   label_status.line_count = (int *)&print_count;  /* # of lines printed      */
  4973.   return (&label_status);                         /* return values */
  4974.                                                            
  4975. }
  4976.  
  4977. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lbl_print ^^^^*/
  4978.  
  4979. #pragma subtitle("lbl_search()")
  4980. #pragma page()
  4981.  
  4982. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv lbl_search vvvv*/
  4983. /*----------------------------------------------------------------------------+
  4984. |                                                                             |
  4985. | SYNOPSIS                                                                    |
  4986. | ~~~~~~~~                                                                    |
  4987. |   #include <stdio.h>                                                        |
  4988. |   #include <string.h>                                                       |
  4989. |   void lbl_search (char *base_file_id, *min_loc, *max_loc);                 |
  4990. |                                                                             |
  4991. | FUNCTION                                                                    |
  4992. | ~~~~~~~~                                                                    |
  4993. |   Searches the file whose name is pointed to by base_file_id for records    |
  4994. |   with a loc1 greater than or equal to min_loc and less than or equal       |
  4995. |   to max_loc, and for each such record create a label node and insert it    |
  4996. |   into a binary tree of label nodes.                                        |
  4997. |                                                                             |
  4998. | RETURNS                                                                     |
  4999. | ~~~~~~~                                                                     |
  5000. |   Nothing.                                                                  |
  5001. |                                                                             |
  5002. |                                                                             |
  5003. | NOTES                                                                       |
  5004. | ~~~~~                                                                       |
  5005. |   Calls a number of functions defined in videocat.c which use nonstandard   |
  5006. |   C86Plus extensions and may not be portable accross compilers and          |
  5007. |   operating systems.                                                        |
  5008. |                                                                             |
  5009. |                                                                             |
  5010. |                                                                             |
  5011. +----------------------------------------------------------------------------*/
  5012.  
  5013. struct LABELNODE *lbl_search (base_file_id, min_loc, max_loc)
  5014.  
  5015.   char                  *base_file_id;    /* path and file name of base file */
  5016.   char                  *min_loc;                        /* minimum location */
  5017.   char                  *max_loc;                        /* maximum location */
  5018.  
  5019. {
  5020.  
  5021.   FILE                  *basef_pointer;      /* stream pointer for base file */
  5022.   struct MOVIERECORD    *base_record;          /* record read from base file */
  5023.   int                    max_comp_result;     /* result of string comparison */
  5024.   int                    min_comp_result;     /* result of string comparison */
  5025.   char                  *iobuf;                       /* buffer for file i/o */
  5026.   extern struct LABELNODE *lbl_tree_insert();    /* func inserts node in tree */
  5027.   struct LABELNODE      *lbltree_root = NULL;    /* root of a tree structure */
  5028.   struct LABELNODE      *label_record;       /* record to contain search key */
  5029.  
  5030.                                               /* allocate memory for records */
  5031.   base_record = (struct MOVIERECORD *)calloc (1,sizeof (struct MOVIERECORD));
  5032.   label_record = (struct LABELNODE *)calloc (1,sizeof (struct LABELNODE));
  5033.   iobuf = calloc (1, BIGBUFF);
  5034.   
  5035.  
  5036.   if ((basef_pointer = fopen (base_file_id, "rb")) == NULL) /* open base file*/
  5037.   {                                                     /* if unsuccessful - */
  5038.     printf ("\nUnable to open base file\n");                    /* warn user */
  5039.     pause();                                                /* wait for user */
  5040.     return (lbltree_root);                     /* return root of binary tree */
  5041.   }
  5042.  
  5043.   setvbuf (basef_pointer, iobuf,_IOFBF, BIGBUFF); /* big buffer for file i/o */
  5044.  
  5045.  
  5046.   while (!(feof (basef_pointer)))            /* loop while not end of file - */
  5047.   {
  5048.  
  5049.       if ((fread ((char *)base_record, sizeof (struct MOVIERECORD),
  5050.            1, basef_pointer)) != 1)      /* read a record from the base file */
  5051.       {                                                   /* if read error - */
  5052.         if (!(feof(basef_pointer)))   /* - and not end of file (normal term) */
  5053.         {
  5054.            printf ("\nError in reading base file\n");           /* warn user */
  5055.            pause();                                         /* wait for user */
  5056.            fcloseall();                                   /* close all files */
  5057.            return (lbltree_root);              /* return root of binary tree */
  5058.         }
  5059.         else break;             /* otherwise (normal) exit loop and continue */
  5060.       }
  5061.       min_comp_result = strcmp (base_record->loc1, min_loc); /* compare loc1 */
  5062.       max_comp_result = strcmp (base_record->loc1, max_loc); /* to min & max */ 
  5063.       if ((min_comp_result >= 0) && (max_comp_result <= 0))  /* if in range -*/
  5064.       {
  5065.         strcpy (label_record->loc1, base_record->loc1);  /* copy loc1, loc2  */
  5066.         strcpy (label_record->loc2, base_record->loc2);  /* and title to node*/
  5067.         strcpy (label_record->title, base_record->title);/* and insert in    */
  5068.         lbltree_root = lbl_tree_insert (lbltree_root, label_record); /* tree */
  5069.       }
  5070.   }  
  5071.  
  5072.         /* shutdown after search completed */
  5073.  
  5074.   free ((char *)base_record);            /* free memory allocated to records */
  5075.   free ((char *)label_record);      /* free memory allocated to label record */
  5076.   free (iobuf);                       /* free memory allocated to i/o buffer */
  5077.  
  5078.   if (fclose (basef_pointer) != NULL)              /* close base file stream */
  5079.     printf ("\nError in closing base file\n");
  5080.  
  5081.   return (lbltree_root);                       /* return root of binary tree */
  5082.  
  5083. }
  5084.  
  5085. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lbl_search ^^^^*/
  5086.  
  5087. #pragma subtitle("lbl_tree_insert()")
  5088. #pragma page()
  5089.  
  5090. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv lbl_tree_insert vvvv*/
  5091. /*----------------------------------------------------------------------------+
  5092. |                                                                             |
  5093. | SYNOPSIS                                                                    |
  5094. | ~~~~~~~~                                                                    |
  5095. |   #include <memory.h>                                                       |
  5096. |   struct LABELNODE  *lbl_tree_insert (struct LABELNODE *lbltree_root,       |
  5097. |                                      struct LABELNODE * new_node)           |
  5098. |                                                                             |
  5099. | FUNCTION                                                                    |
  5100. | ~~~~~~~~                                                                    |
  5101. |   Inserts a transaction pointed to by new_node into a binary tree           |
  5102. |   pointed to by lbltree_root.                                               |
  5103. |                                                                             |
  5104. |                                                                             |
  5105. | RETURNS                                                                     |
  5106. | ~~~~~~~                                                                     |
  5107. |   Pointer to the root of the binary tree structure.                         |
  5108. |                                                                             |
  5109. |                                                                             |
  5110. |                                                                             |
  5111. | NOTES                                                                       |
  5112. | ~~~~~                                                                       |
  5113. |   Memcpy() is declared in memory.h.   LABELNODE is a structure defined      |
  5114. |   in videocat.c.                                                            |
  5115. |                                                                             |
  5116. |                                                                             |
  5117. |                                                                             |
  5118. |                                                                             |
  5119. +----------------------------------------------------------------------------*/
  5120.  
  5121. struct LABELNODE *lbl_tree_insert (lbltree_root, new_node)
  5122.                                                    /* insert node in lbltree */
  5123.  
  5124.   struct LABELNODE     *lbltree_root;            /* root of a tree structure */
  5125.   struct LABELNODE     *new_node;                    /* ptr to a transaction */
  5126.  
  5127. {
  5128.   int                   cond;                   /* comparison condition code */
  5129.   extern int            lbl_loc_comp();             /* func to compare nodes */
  5130.   static int            out_of_memory = FALSE;
  5131.   SEL                   sel;                        /* memory block selector */
  5132.  
  5133.   if (lbltree_root == NULL)                  /* if tree root is null pointer */
  5134.     {
  5135.       out_of_memory = DosAllocSeg ((sizeof (struct LABELNODE)),&sel,0);
  5136.       if (out_of_memory)
  5137.       {
  5138.         printf ("Running out of memory....\n");
  5139.         return (lbltree_root);                     /* return pointer to root */
  5140.       }
  5141.       lbltree_root = MAKEP (sel,0);          /* make pointer out of selector */
  5142.       memcpy ((char *)lbltree_root, (char *)new_node,
  5143.               sizeof(struct LABELNODE));                        /* copy node */
  5144.       lbltree_root->sel = sel;
  5145.       lbltree_root->lnode = lbltree_root->rnode = NULL;      /* nodes = Null */
  5146.     }
  5147.   else if ((cond = lbl_loc_comp (new_node, lbltree_root)) < 0)
  5148.     lbltree_root->lnode = lbl_tree_insert (lbltree_root->lnode, new_node);
  5149.   else if (cond >= 0)   /* if new greater than root insert new at right node */
  5150.     lbltree_root->rnode = lbl_tree_insert (lbltree_root->rnode, new_node);
  5151.   return (lbltree_root);                           /* return pointer to root */
  5152.  
  5153. }
  5154.  
  5155. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lbl_tree_insert ^^^^*/
  5156.  
  5157. #pragma subtitle("main_menu()")
  5158. #pragma page()
  5159.  
  5160. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv main_menu vvvv*/
  5161. /*----------------------------------------------------------------------------+
  5162. |                                                                             |
  5163. | SYNOPSIS                                                                    |
  5164. | ~~~~~~~~                                                                    |
  5165. |   #include <stdio.h>                                                        |
  5166. |   void main_menu()                                                          |
  5167. |                                                                             |
  5168. | FUNCTION                                                                    |
  5169. | ~~~~~~~~                                                                    |
  5170. |   Clears screen, opens window, draws box, and displays main menu.           |
  5171. |                                                                             |
  5172. |                                                                             |
  5173. |                                                                             |
  5174. | RETURNS                                                                     |
  5175. | ~~~~~~~                                                                     |
  5176. |   Nothing.                                                                  |
  5177. |                                                                             |
  5178. |                                                                             |
  5179. |                                                                             |
  5180. | NOTES                                                                       |
  5181. | ~~~~~                                                                       |
  5182. |   Calls functions using nonstanard C extensions.  May not be portable       |
  5183. |   accross operating systems and compilers.                                  |
  5184. |                                                                             |
  5185. |                                                                             |
  5186. |                                                                             |
  5187. |                                                                             |
  5188. +----------------------------------------------------------------------------*/
  5189.  
  5190. void main_menu()                                        /* display main menu */
  5191.  
  5192. {
  5193.   USHORT            cbString;                           /* string byte count */
  5194.   char              char_buff[256];                         /* string buffer */
  5195.   extern void       clear_screen();    /* func clears screen and sets colors */
  5196.   HVIO              hvio = 0;                                /* video handle */
  5197.   extern void       draw_box();                  /* func draws box on screen */
  5198.   extern void       set_cursor();               /* func sets cursor position */
  5199.   extern void       window();         /* func opens window on screen display */
  5200.  
  5201.   set_border (BLACK);
  5202.   clear_screen (LWHITE, BLACK);                 /* clear screen & set colors */
  5203.   window (10,70,3,20,WHITE,BLUE);                             /* open window */
  5204.   draw_box ('l',11,69,3,20);                           /* draw box in window */
  5205.  
  5206.   sprintf (char_buff, "MAIN MENU");                  /* display menu caption */
  5207.   cbString = (USHORT)strlen(char_buff);
  5208.   VioWrtCharStr (char_buff,cbString,5,35,hvio);
  5209.  
  5210.   sprintf (char_buff, "A  =  Add a new record to the catalog.");
  5211.   cbString = (USHORT)strlen(char_buff);
  5212.   VioWrtCharStr (char_buff,cbString,8,14,hvio);
  5213.  
  5214.   sprintf (char_buff, "C  =  Change an existing record in the catalog.");
  5215.   cbString = (USHORT)strlen(char_buff);
  5216.   VioWrtCharStr (char_buff,cbString,9,14,hvio);
  5217.  
  5218.   sprintf (char_buff, "D  =  Delete an existing record in the catalog.");
  5219.   cbString = (USHORT)strlen(char_buff);
  5220.   VioWrtCharStr (char_buff,cbString,10,14,hvio);
  5221.  
  5222.   sprintf (char_buff, "F  =  File conversion from prior version.");
  5223.   cbString = (USHORT)strlen(char_buff);
  5224.   VioWrtCharStr (char_buff,cbString,11,14,hvio);
  5225.  
  5226.   sprintf (char_buff, "L  =  Label maker.");
  5227.   cbString = (USHORT)strlen(char_buff);
  5228.   VioWrtCharStr (char_buff,cbString,12,14,hvio);
  5229.  
  5230.   sprintf (char_buff, "R  =  Review current changes not yet updated.");
  5231.   cbString = (USHORT)strlen(char_buff);
  5232.   VioWrtCharStr (char_buff,cbString,13,14,hvio);
  5233.  
  5234.   sprintf (char_buff, "S  =  Search catalog.");
  5235.   cbString = (USHORT)strlen(char_buff);
  5236.   VioWrtCharStr (char_buff,cbString,14,14,hvio);
  5237.                                       
  5238.   sprintf (char_buff, "T  =  Tally statistics for catalog content.");
  5239.   cbString = (USHORT)strlen(char_buff);
  5240.   VioWrtCharStr (char_buff,cbString,15,14,hvio);
  5241.  
  5242.   sprintf (char_buff, "U  =  Update catalog with current changes.");
  5243.   cbString = (USHORT)strlen(char_buff);
  5244.   VioWrtCharStr (char_buff,cbString,16,14,hvio);
  5245.  
  5246.   sprintf (char_buff, "W  =  Whole catalog listing.           ");
  5247.   cbString = (USHORT)strlen(char_buff);
  5248.   VioWrtCharStr (char_buff,cbString,17,14,hvio);
  5249.  
  5250.   sprintf (char_buff, "E  =  Exit from program without further updating.");
  5251.   cbString = (USHORT)strlen(char_buff);
  5252.   VioWrtCharStr (char_buff,cbString,18,14,hvio);
  5253.  
  5254.   sprintf (char_buff,"Enter code -> ");
  5255.   cbString = (USHORT)strlen(char_buff);
  5256.   VioWrtCharStr (char_buff,cbString,22,10,hvio);
  5257.   VioSetCurPos (22,(10 +cbString), hvio);
  5258.  
  5259. }    
  5260. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ main_menu ^^^^*/
  5261.  
  5262. #pragma subtitle("name_out()")
  5263. #pragma page()
  5264.  
  5265. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv name_out vvvv*/
  5266.  
  5267. /*----------------------------------------------------------------------------+
  5268. |                                                                             |
  5269. | SYNOPSIS                                                                    |
  5270. | ~~~~~~~~                                                                    |
  5271. |   #include <stdio.h>                                                        |
  5272. |   #include <string.h>                                                       |
  5273. |   void name_out (char *name_ptr)                                            |
  5274. |                                                                             |
  5275. | FUNCTION                                                                    |
  5276. | ~~~~~~~~                                                                    |
  5277. |   Converts the name at name_ptr from record format ["LAST,FIRST"] to        |
  5278. |   output format ["FIRST LAST"].                                             |
  5279. |                                                                             |
  5280. |                                                                             |
  5281. | RETURNS                                                                     |
  5282. | ~~~~~~~                                                                     |
  5283. |   Nothing.                                                                  |
  5284. |                                                                             |
  5285. |                                                                             |
  5286. | NOTES                                                                       |
  5287. | ~~~~~                                                                       |
  5288. |                                                                             |
  5289. |   Uses functions declared in string.h and trim(), a function defined        |
  5290. |   in videocat.c.  Uses only ANSI standard functions.  Should be portable.   |
  5291. |                                                                             |
  5292. |                                                                             |
  5293. |                                                                             |
  5294. +----------------------------------------------------------------------------*/
  5295.  
  5296. void name_out (name_ptr)                 /* converts name from record format */
  5297.  
  5298.   char             *name_ptr;                 /* ptr to name to be converted */
  5299.  
  5300. {
  5301.   int               f_count = 0;               /* first name character count */
  5302.   char              first_name [INPUTLENGTH];           /* first name buffer */
  5303.   int               l_count = 0;                /* last name character count */
  5304.   char              last_name [INPUTLENGTH];             /* last name buffer */          
  5305.   int               max;                    /* maximum # chars to be scanned */
  5306.   extern void       trim();             /* func trims lead & trail whitespace*/
  5307.   int               w_count = 0;               /* whole name character count */
  5308.  
  5309.   max = strlen (name_ptr);             /* don't scan more chars than in name */
  5310.  
  5311.             /* extract last name */
  5312.             
  5313.   while ((w_count <= max) && (name_ptr [w_count] != ',')) /* while no comma- */
  5314.   {
  5315.     last_name [l_count] = name_ptr [w_count];     /* copy chars to last name */
  5316.     l_count++;
  5317.     w_count++;
  5318.   }
  5319.   last_name [l_count] = '\0';                      /* append null terminator */
  5320.   trim (last_name);                                        /* trim last name */
  5321.  
  5322.             /* extract first name */
  5323.             
  5324.   w_count++;                                              /* skip over comma */
  5325.   while (w_count <= max)                              /* for rest of chars - */
  5326.   {
  5327.     first_name [f_count] = name_ptr [w_count];       /* - copy to first name */
  5328.     f_count++;
  5329.     w_count++;
  5330.   }
  5331.   first_name [f_count] = '\0';                     /* append null terminator */ 
  5332.   trim (first_name);                                      /* trim first name */
  5333.         
  5334.             /* assemble converted name */
  5335.                     
  5336.   strcpy (name_ptr, first_name);                  /* copy first name to name */
  5337.   strcat (name_ptr, " ");                        /* append 1 space separator */  
  5338.   strcat (name_ptr, last_name);                          /* append last name */
  5339.   trim (name_ptr);                                              /* trim name */
  5340.  
  5341. }
  5342.  
  5343. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ name_out ^^^^*/
  5344.  
  5345. #pragma subtitle("outopt()")
  5346. #pragma page()
  5347.  
  5348. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv outopt vvvv*/
  5349.  
  5350. /*----------------------------------------------------------------------------+
  5351. |                                                                             |
  5352. | SYNOPSIS                                                                    |
  5353. | ~~~~~~~~                                                                    |
  5354. |   #include <stdio.h>                                                        |
  5355. |   char outopt();                                                            |
  5356. |                                                                             |
  5357. | FUNCTION                                                                    |
  5358. | ~~~~~~~~                                                                    |
  5359. |   Displays menu of output options, gets user choice, and returns            |
  5360. |   character code for choice.                                                |
  5361. |                                                                             |
  5362. |                                                                             |
  5363. | RETURNS                                                                     |
  5364. | ~~~~~~~                                                                     |
  5365. |   Character code for output option chosen by user.                          |
  5366. |                                                                             |
  5367. |                                                                             |
  5368. |                                                                             |
  5369. | NOTES                                                                       |
  5370. | ~~~~~                                                                       |
  5371. |                                                                             |
  5372. |   Calls functions which use nonstandard C extensions.  May not be           |
  5373. |   portable accross operating systems and compilers.                         |
  5374. |                                                                             |
  5375. |                                                                             |
  5376. |                                                                             |
  5377. +----------------------------------------------------------------------------*/
  5378. char outopt()
  5379.  
  5380. {
  5381.  
  5382.   extern void            clear_screen();/* func clears screen and sets colors*/
  5383.   extern void            draw_box();             /* func draws box on screen */
  5384.   char                   output_type;                /* code for output type */
  5385.   char                   response [INPUTLENGTH];/* buffer for keyboard input */
  5386.   extern char            search_key();
  5387.   extern void            set_cursor();          /* func sets cursor position */
  5388.   extern void            trim(); /* func trims leading & trailing whitespace */
  5389.   int                    valid_code = FALSE;  /* boolean flag for valid code */
  5390.   extern void            window();    /* func opens window on screen display */
  5391.  
  5392.          /* display output option menu and get user choice */
  5393.          
  5394.   valid_code = FALSE;                        /* set valid code flag to false */
  5395.   while (!valid_code)                      /* loop until valid code selected */
  5396.   {
  5397.     clear_screen (LWHITE, BLACK);               /* clear screen & set colors */
  5398.     window (10,70,3,18,LBLUE,BLACK);                          /* open window */
  5399.     draw_box ('l',11,69,3,18);                         /* draw box in window */
  5400.     set_cursor (5,33,0);                                  /* position cursor */
  5401.     printf ("OUTPUT OPTIONS");                       /* display menu caption */
  5402.     set_cursor (10,14,0);                                     /* move cursor */
  5403.     printf ("S  =  Screen output (pauses when screen full)");/* print choice */
  5404.     set_cursor (11,14,0);                                     /* move cursor */
  5405.     printf ("C  =  Continuous screen output (no pausing). ");/* print choice */
  5406.     set_cursor (12,14,0);                                     /* move cursor */
  5407.     printf ("P  =  Printer output.                ");        /* print choice */
  5408.     set_cursor (21, 10, 0);                                   /* move cursor */
  5409.     printf ("Enter code -> ");                /* prompt user to enter choice */
  5410.     gets (response);                                    /* get user response */
  5411.     trim (response);                   /* trim whitespace from user response */
  5412.     output_type = toupper (response [0]);         /* first character is code */
  5413.     switch (output_type)                         /* select according to code */
  5414.     {
  5415.       case 'S' :                     /* screen or continuous output selected */
  5416.       case 'C' :
  5417.       case 'P' :
  5418.         valid_code = TRUE;                    /* set valid code flag to true */
  5419.         break;                                             /* exit selection */
  5420.  
  5421.       default :                                             /* no code match */
  5422.    
  5423.         printf ("\nINVALID CODE\n");                            /* warn user */
  5424.         pause();                                            /* wait for user */
  5425.         break;                                             /* exit selection */
  5426.     }         
  5427.   }
  5428.   return (output_type);
  5429. }
  5430. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ outopt ^^^^*/
  5431.  
  5432. #pragma subtitle("pause()")
  5433. #pragma page()
  5434.  
  5435. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv pause vvvv*/
  5436. /*----------------------------------------------------------------------------+
  5437. |                                                                             |
  5438. | SYNOPSIS                                                                    |
  5439. | ~~~~~~~~                                                                    |
  5440. |   #include <stdio.h>                                                        |
  5441. |   char pause();                                                             |
  5442. |                                                                             |
  5443. | FUNCTION                                                                    |
  5444. | ~~~~~~~~                                                                    |
  5445. |   Prompts user and pauses program execution until the user enters           |
  5446. |   a carriage return.                                                        |
  5447. |                                                                             |
  5448. |                                                                             |
  5449. | RETURNS                                                                     |
  5450. | ~~~~~~~                                                                     |
  5451. |                       The first character entered by the user.              |
  5452. |                                                                             |
  5453. |                                                                             |
  5454. |                                                                             |
  5455. | NOTES                                                                       |
  5456. | ~~~~~                                                                       |
  5457. |   Used to pause program execution temporarily, permitting the user          |
  5458. |   to signal when ready to continue, such as after reading text              |
  5459. |   displayed on the screen.  Although the function returns the first         |
  5460. |   character entered, the return value is not likely to be useful.           |
  5461. |                                                                             |
  5462. |                                                                             |
  5463. +----------------------------------------------------------------------------*/
  5464.  
  5465. char pause()                         /* pause for user */
  5466.  
  5467. {
  5468.   int       fgetc();               /* ANSI func returns one char from stream */
  5469.   char      go_ahead;                           /* character entered by user */
  5470.   int       printf();                          /* ANSI formatted output func */
  5471.   
  5472.   printf (" Enter/<return> to continue");                     /* prompt user */
  5473.   go_ahead = (char)fgetc(stdin);              /* wait for entry of character */
  5474.   return (go_ahead);                             /* return character entered */
  5475.  
  5476. }
  5477.  
  5478. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pause ^^^^*/
  5479.  
  5480. #pragma subtitle("print_rec()")
  5481. #pragma page()
  5482.  
  5483. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv print_rec vvvv*/
  5484. /*----------------------------------------------------------------------------+
  5485. |                                                                             |
  5486. | SYNOPSIS                                                                    |
  5487. | ~~~~~~~~                                                                    |
  5488. |   #include <stdio.h>                                                        |
  5489. |   #include <string.h>                                                       |
  5490. |   void print_rec(struct MOVIERECORD *rec_ptr, FILE *print_pointer)          |
  5491. |                                                                             |
  5492. | FUNCTION                                                                    |
  5493. | ~~~~~~~~                                                                    |
  5494. |   Prints the data contained in the record pointed to by rec_ptr             |
  5495. |   on the printer via the stream print_pointer.                              |
  5496. |                                                                             |
  5497. |                                                                             |
  5498. | RETURNS                                                                     |
  5499. | ~~~~~~~                                                                     |
  5500. |   Nothing.                                                                  |
  5501. |                                                                             |
  5502. |                                                                             |
  5503. |                                                                             |
  5504. | NOTES                                                                       |
  5505. | ~~~~~                                                                       |
  5506. |   Uses a number of functions defined in videocat.c.  All use only           |
  5507. |   ANSI standard functions and should be portable.                           |
  5508. |                                                                             |
  5509. |                                                                             |
  5510. |                                                                             |
  5511. |                                                                             |
  5512. +----------------------------------------------------------------------------*/
  5513.  
  5514. void print_rec (rec_ptr, print_pointer)
  5515.  
  5516.   struct MOVIERECORD  *rec_ptr;                           /* ptr to a record */
  5517.   FILE                *print_pointer;                      /* ptr to printer */
  5518.  
  5519.  
  5520. {
  5521.   int                   count;                                    /* counter */
  5522.   extern void           name_out();             /* func converts name format */
  5523.   extern void           trim();           /* func trims lead & trail whitesp */
  5524.   char                  star1_disp [INPUTLENGTH];   /*-----------------------*/
  5525.   char                  star2_disp [INPUTLENGTH];   /*  buffers in which the */
  5526.   char                  star3_disp [INPUTLENGTH];   /*  various elements in  */
  5527.   char                  dir_disp   [INPUTLENGTH];   /*  a MOVIETRANS struct  */
  5528.   char                  subj_disp  [INPUTLENGTH];   /*  are converted from   */
  5529.   char                  form_disp  [INPUTLENGTH];   /*  record format to a   */
  5530.   char                  type_disp  [INPUTLENGTH];   /*  display format.      */
  5531.   char                  rating_disp[INPUTLENGTH];   /*-----------------------*/
  5532.   char                  mpaa_disp  [INPUTLENGTH];  
  5533.   
  5534.  
  5535.   strcpy (star1_disp, rec_ptr->star1);                    /* get star1  name */
  5536.   name_out (star1_disp);                          /* and convert for display */
  5537.  
  5538.   strcpy (star2_disp, rec_ptr->star2);                    /* get star2  name */
  5539.   name_out (star2_disp);                          /* and convert for display */
  5540.  
  5541.   strcpy (star3_disp, rec_ptr->star3);                    /* get star3  name */
  5542.   name_out (star3_disp);                          /* and convert for display */
  5543.  
  5544.   strcpy (dir_disp, rec_ptr->director);                 /* get director name */
  5545.   name_out (dir_disp);                            /* and convert for display */
  5546.   while (strlen (dir_disp) < 24)                /* pad director display name */
  5547.     strcat (dir_disp, " ");                          /* with trailing blanks */
  5548.   
  5549.   for (count = 0; count < CODENUMBER; count++)       /* look up subject code */
  5550.     if (rec_ptr->subject == codes [count])                 /* if found, copy */
  5551.           strcpy (subj_disp, subjects [count]);                /*  subject   */
  5552.   trim (subj_disp);                                          /* trim subject */
  5553.  
  5554.   for (count = 0; count < FORMNUMBER; count++)       /* look up form code    */
  5555.     if (rec_ptr->form == codes [count])                  /* if found, copy   */
  5556.       strcpy (form_disp, forms [count]);          /* corresponding form      */
  5557.   trim (form_disp);                                  /* trim form            */
  5558.   
  5559.   strcpy (type_disp, subj_disp);             /* copy subject to type buffer  */
  5560.       strcat (type_disp, " ");               /* append 1 blank space to type */
  5561.   strcat (type_disp, form_disp);             /* append form to type buffer   */
  5562.   while (strlen (type_disp) < 26)            /* pad type bufer with trailing */
  5563.     strcat (type_disp, " ");                 /* blanks to width 26           */
  5564.  
  5565.   strcpy (mpaa_disp, " ");                       /* initialize mpaa as blank */
  5566.   for (count = 0; count < MPAANUMBER; count++)       /* look up mpaa    code */
  5567.     if (rec_ptr->mpaa_code == codes [count])               /* if found, copy */
  5568.           strcpy (mpaa_disp, mpaa_codes [count]);              /*  mpaa      */
  5569.   trim (mpaa_disp);                                          /* trim mpaa    */
  5570.   while (strlen (mpaa_disp) < 20)            /* pad type bufer with trailing */
  5571.     strcat (mpaa_disp, " ");                 /* blanks to width 20           */
  5572.  
  5573.  
  5574.   for (count = 0; count < RATINGNUMBER; count++)         /* look up rating   */
  5575.     if (rec_ptr->rating == codes [count])                  /* if found copy  */
  5576.       strcpy (rating_disp, ratings [count]);         /* corresponding rating */
  5577.  
  5578.  
  5579.                 /* print data in display format */
  5580.   fprintf (print_pointer,  "          %s               [%s]\n",
  5581.              rec_ptr->title, rec_ptr->year); 
  5582.   fprintf (print_pointer, "          %s%s%s\n",
  5583.      type_disp, mpaa_disp, rating_disp);
  5584.   fprintf (print_pointer, "          Starring: %s, %s, %s\n", star1_disp,
  5585.                                      star2_disp, star3_disp);
  5586.   fprintf(print_pointer,"          Director: %s Cassette: %s Index: %s\n",
  5587.       dir_disp, rec_ptr->loc1, rec_ptr->loc2); 
  5588.  
  5589. }
  5590.  
  5591. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ print_rec ^^^^*/
  5592.  
  5593. #pragma subtitle("prnopt()")
  5594. #pragma page()
  5595.  
  5596. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv prnopt vvvv*/
  5597.  
  5598. /*----------------------------------------------------------------------------+
  5599. |                                                                             |
  5600. | SYNOPSIS                                                                    |
  5601. | ~~~~~~~~                                                                    |
  5602. |   #include <stdio.h>                                                        |
  5603. |   char prnopt();                                                            |
  5604. |                                                                             |
  5605. | FUNCTION                                                                    |
  5606. | ~~~~~~~~                                                                    |
  5607. |   Displays menu of printer options, gets user choice, and returns           |
  5608. |   character code for choice.                                                |
  5609. |                                                                             |
  5610. |                                                                             |
  5611. | RETURNS                                                                     |
  5612. | ~~~~~~~                                                                     |
  5613. |   Character code for output option chosen by user.                          |
  5614. |                                                                             |
  5615. |                                                                             |
  5616. |                                                                             |
  5617. | NOTES                                                                       |
  5618. | ~~~~~                                                                       |
  5619. |                                                                             |
  5620. |   Calls functions which use nonstandard C extensions.  May not be           |
  5621. |   portable accross operating systems and compilers.                         |
  5622. |                                                                             |
  5623. |                                                                             |
  5624. |                                                                             |
  5625. +----------------------------------------------------------------------------*/
  5626. char prnopt()
  5627.  
  5628. {
  5629.  
  5630.   extern void            clear_screen();/* func clears screen and sets colors*/
  5631.   extern void            draw_box();             /* func draws box on screen */
  5632.   char                   output_type;                /* code for output type */
  5633.   char                   response [INPUTLENGTH];/* buffer for keyboard input */
  5634.   extern char            search_key();
  5635.   extern void            set_cursor();          /* func sets cursor position */
  5636.   extern void            trim(); /* func trims leading & trailing whitespace */
  5637.   int                    valid_code = FALSE;  /* boolean flag for valid code */
  5638.   extern void            window();    /* func opens window on screen display */
  5639.  
  5640.          /* display output option menu and get user choice */
  5641.          
  5642.   valid_code = FALSE;                        /* set valid code flag to false */
  5643.   while (!valid_code)                      /* loop until valid code selected */
  5644.   {
  5645.     clear_screen (LWHITE, BLACK);               /* clear screen & set colors */
  5646.     window (10,70,3,18,LBLUE,BLACK);                          /* open window */
  5647.     draw_box ('l',11,69,3,18);                         /* draw box in window */
  5648.     set_cursor (5,33,0);                                  /* position cursor */
  5649.     printf ("PRINTER OPTIONS");                      /* display menu caption */
  5650.     set_cursor (10,14,0);                                     /* move cursor */
  5651.     printf ("A  =  ASCII (standard) printer");              ;/* print choice */
  5652.     set_cursor (11,14,0);                                     /* move cursor */
  5653.     printf ("H  =  Hewlett Packard Laserjet II");            /* print choice */
  5654.     set_cursor (21, 10, 0);                                   /* move cursor */
  5655.     printf ("Enter code -> ");                /* prompt user to enter choice */
  5656.     gets (response);                                    /* get user response */
  5657.     trim (response);                   /* trim whitespace from user response */
  5658.     output_type = toupper (response [0]);         /* first character is code */
  5659.     switch (output_type)                         /* select according to code */
  5660.     {
  5661.       case 'A' :                     /* screen or continuous output selected */
  5662.       case 'H' :
  5663.         valid_code = TRUE;                    /* set valid code flag to true */
  5664.         break;                                             /* exit selection */
  5665.  
  5666.       default :                                             /* no code match */
  5667.    
  5668.         printf ("\nINVALID CODE\n");                            /* warn user */
  5669.         pause();                                            /* wait for user */
  5670.         break;                                             /* exit selection */
  5671.     }         
  5672.   }
  5673.   return (output_type);
  5674. }
  5675. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ prnopt ^^^^*/
  5676.  
  5677. #pragma subtitle("qpause()")
  5678. #pragma page()
  5679.  
  5680. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv qpause vvvv*/
  5681. /*----------------------------------------------------------------------------+
  5682. |                                                                             |
  5683. | SYNOPSIS                                                                    |
  5684. | ~~~~~~~~                                                                    |
  5685. |   #include <stdio.h>                                                        |
  5686. |   char qpause();                                                            |
  5687. | FUNCTION                                                                    |
  5688. | ~~~~~~~~                                                                    |
  5689. |   Prompts user and pauses program execution until the user enters           |
  5690. |   a carriage return to continue or Q to pause.                              |
  5691. |                                                                             |
  5692. |                                                                             |
  5693. | RETURNS                                                                     |
  5694. | ~~~~~~~                                                                     |
  5695. |                       The first character entered by the user.              |
  5696. |                                                                             |
  5697. |                                                                             |
  5698. |                                                                             |
  5699. | NOTES                                                                       |
  5700. | ~~~~~                                                                       |
  5701. |   Used to pause program execution temporarily, permitting the user          |
  5702. |   to signal when ready to continue, such as after reading text              |
  5703. |   displayed on the screen.  If the letter is Q, the return value indicates  |
  5704. |   that the user wishes to quit the current routine.                         |
  5705. |                                                                             |
  5706. |                                                                             |
  5707. +----------------------------------------------------------------------------*/
  5708.  
  5709. char qpause()                         /* pause for user to continue or quit  */
  5710.  
  5711. {
  5712.   char      go_ahead;                           /* character entered by user */
  5713.   char      input[80];                                       /* input buffer */
  5714.  
  5715.   printf (" <return> to continue - Q <return> to quit -> ");  /* prompt user */
  5716.   gets (input);                               /* wait for entry of character */
  5717.   go_ahead = toupper(input[0]);                      /* convert to uppercase */
  5718.   return (go_ahead);                             /* return character entered */
  5719.  
  5720. }
  5721.  
  5722. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ qpause ^^^^*/
  5723.  
  5724. #pragma subtitle("rec_comp()")
  5725. #pragma page()
  5726.  
  5727. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv rec_comp vvvv*/
  5728.  
  5729. /*----------------------------------------------------------------------------+
  5730. |                                                                             |
  5731. | SYNOPSIS                                                                    |
  5732. | ~~~~~~~~                                                                    |
  5733. |   #include <stdio.h>                                                        |
  5734. |   #include <string.h>                                                       |
  5735. |   #include <videocat.h>                                                     |
  5736. |   int rec_comp  (struct MOVIERECORD *rec1, struct MOVIERECORD *rec2)        |
  5737. |                                                                             |
  5738. | FUNCTION                                                                    |
  5739. | ~~~~~~~~                                                                    |
  5740. |  Compares the records pointed to by rec1 and rec2, first by title           |
  5741. |  (in ASCII collating sequence), then by year if titles are equal.           |
  5742. |                                                                             |
  5743. |                                                                             |
  5744. | RETURNS                                                                     |
  5745. | ~~~~~~~                                                                     |
  5746. |   less than zero if rec1 is less than rec2                                  |
  5747. |   zero if rec1 is equal to rec2                                             |
  5748. |   greater than zero if rec1 is greater than rec2                            |
  5749. |                                                                             |
  5750. | NOTES                                                                       |
  5751. | ~~~~~                                                                       |
  5752. |   Comparison is used for sorting records in alphabetical sequence by        |
  5753. |   title.  Because of "remakes" two movies are allowed to have the same      |
  5754. |   title and they will be sequenced according to year of production.         |
  5755. |   When both title and year are the same, it is assumed that the records     |
  5756. |   both identify the same movie.                                             |
  5757. |                                                                             |
  5758. +----------------------------------------------------------------------------*/
  5759.  
  5760. int rec_comp (rec1, rec2)
  5761.  
  5762. struct MOVIERECORD *rec1, *rec2;    /* ptrs to two records */
  5763.  
  5764. {
  5765.   int comp_result;                  /* result of comparison */
  5766.  
  5767.   if ((comp_result = strcmp (rec1->title, rec2->title)) == 0)
  5768.     comp_result = strcmp (rec1->year, rec2->year);
  5769.  
  5770.   return (comp_result);
  5771. }
  5772.  
  5773. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ rec_comp ^^^^*/
  5774.  
  5775. #pragma subtitle("search()")
  5776. #pragma page()
  5777.  
  5778. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv search vvvv*/
  5779. /*----------------------------------------------------------------------------+
  5780. |                                                                             |
  5781. | SYNOPSIS                                                                    |
  5782. | ~~~~~~~~                                                                    |
  5783. |   #include <stdio.h>                                                        |
  5784. |   #include <string.h>                                                       |
  5785. |   #include <time.h>                                                         |
  5786. |   void search (char *base_file_id);                                         |
  5787. |                                                                             |
  5788. | FUNCTION                                                                    |
  5789. | ~~~~~~~~                                                                    |
  5790. |   Prompts the user for the the key to be searched for and the type of       |
  5791. |   output desired (continuous screen, paused screen, or printer), then       |
  5792. |   reads all records in the file identified by base_file_id and displays     |
  5793. |   each record which matches the designated key.                             |
  5794. |                                                                             |
  5795. | RETURNS                                                                     |
  5796. | ~~~~~~~                                                                     |
  5797. |   Nothing.                                                                  |
  5798. |                                                                             |
  5799. |                                                                             |
  5800. | NOTES                                                                       |
  5801. | ~~~~~                                                                       |
  5802. |   Calls a number of functions defined in videocat.c which use nonstandard   |
  5803. |   MSC     extensions and may not be portable accross compilers and          |
  5804. |   operating systems.                                                        |
  5805. |                                                                             |
  5806. |                                                                             |
  5807. |                                                                             |
  5808. +----------------------------------------------------------------------------*/
  5809.  
  5810. void search (base_file_id)
  5811.  
  5812.   char                  *base_file_id;    /* path and file name of base file */
  5813.  
  5814. {
  5815.  
  5816.   FILE                  *basef_pointer;      /* stream pointer for base file */
  5817.   struct MOVIERECORD    *base_record;          /* record read from base file */
  5818.   USHORT                 cbString;                      /* string byte count */
  5819.   char                  *char_buff;                         /* string buffer */   
  5820.   extern void            clear_screen();/* func clears screen and sets colors*/
  5821.   char                  *comp_ptr;  /* ptr to substring returned by strstr() */
  5822.   int                    comp_result;         /* result of string comparison */
  5823.   extern void            disp_rec();
  5824.   int                    found;            /* boolean flag for search result */
  5825.   char                   go_ahead = ' ';/* quit or go ahead signal from user */
  5826.   HVIO                   hvio = 0;                           /* video handle */
  5827.   char                  *iobuf;                       /* buffer for file i/o */
  5828.   int                    out_count = 0;        /* counter for records output */
  5829.   char                   output_type = '\0';         /* code for output type */
  5830.   extern char            outopt();   /* func gets user choice of output type */
  5831.   extern char            pause();                    /* func pauses for user */
  5832.   extern void            print_rec();       /* func prints record on printer */
  5833.   int   print_handle;                             /* file handle for printer */
  5834.   FILE *print_pointer;                                 /* stream for printer */
  5835.   extern char            qpause();       /* func pauses for go-ahead or quit */
  5836.   extern char            search_key();    /* func gets key record for search */
  5837.   struct MOVIERECORD    *s_key_record;       /* record to contain search key */
  5838.   char                   s_type = '\0';           /* code for type of search */
  5839.   extern void            set_cursor();          /* func sets cursor position */
  5840.   long                   time_1;                   /* time marker in seconds */
  5841.   long                   time_2;                   /* time marker in seconds */
  5842.  
  5843.   char_buff = (char *) calloc (1, 0x100);
  5844.                                               /* allocate memory for records */
  5845.   base_record = (struct MOVIERECORD *)calloc (1,sizeof (struct MOVIERECORD));
  5846.   s_key_record = (struct MOVIERECORD *)calloc (1,sizeof (struct MOVIERECORD));
  5847.   iobuf = calloc (1, BIGBUFF);
  5848.   
  5849.   s_type = search_key (s_key_record);
  5850.   if (s_type == 'E')
  5851.     return;
  5852.  
  5853.   VioSetCurPos (22,0,hvio);
  5854.   output_type = outopt();
  5855.   if (output_type == 'P')
  5856.   {
  5857.     print_handle = open ("PRN", O_WRONLY);               /* open file handle */
  5858.     if (print_handle == -1)                           /* test for open error */
  5859.       perror ("open failed on PRN");
  5860.     print_pointer = fdopen (print_handle, "w");          /* associate stream */
  5861.     if (print_pointer == NULL)                             /* test for error */
  5862.     {
  5863.       perror ("fopen failed on print_handle");
  5864.       pause();                                              /* wait for user */
  5865.       return;                                       /* return to main module */
  5866.     }                         
  5867.   }  
  5868.             /* search records in base file for key matches */
  5869.  
  5870.   if ((basef_pointer = fopen (base_file_id, "rb")) == NULL) /* open base file*/
  5871.   {                                                     /* if unsuccessful - */
  5872.     printf ("\nUnable to open base file\n");                    /* warn user */
  5873.     pause();                                                /* wait for user */
  5874.     return;                                         /* return to main module */
  5875.   }
  5876.  
  5877.   setvbuf (basef_pointer, iobuf,_IOFBF, BIGBUFF); /* big buffer for file i/o */
  5878.  
  5879.   set_border (BLACK);
  5880.   clear_screen (WHITE,BLACK);
  5881.   window (0,79,0,0,LGREEN,BLACK);
  5882.   VioSetCurPos (22,0,hvio);
  5883.   if (output_type == 'P')
  5884.     printf ("Search results being printed (printer must be ready)...");
  5885.   else
  5886.     printf ("Search results being displayed on screen...");
  5887.  
  5888.   while ((!(feof (basef_pointer)))           /* loop while not end of file - */
  5889.          && (go_ahead != 'Q'))               /* and no quit signal from user */           
  5890.   {
  5891.     found = FALSE;                                /* set found flag to false */
  5892.  
  5893.       if ((fread ((char *)base_record, sizeof (struct MOVIERECORD),
  5894.            1, basef_pointer)) != 1)      /* read a record from the base file */
  5895.       {                                                   /* if read error - */
  5896.         if (!(feof(basef_pointer)))   /* - and not end of file (normal term) */
  5897.         {
  5898.            printf ("\nError in reading base file\n");           /* warn user */
  5899.            pause();                                         /* wait for user */
  5900.            fcloseall();                                   /* close all files */
  5901.            return;                                                  /* abort */
  5902.         }
  5903.         else break;             /* otherwise (normal) exit loop and continue */
  5904.       }
  5905.  
  5906.     switch (s_type)        /* selection action according to search type code */
  5907.     {
  5908.       case 'T' :                                         /* for title search */
  5909.  
  5910.         comp_ptr = strstr (base_record->title, s_key_record->title);
  5911.         if (comp_ptr != NULL)  /* if search title is substring of base title */
  5912.           found = TRUE;                              /* match has been found */
  5913.         break;                                      /* exit switch selection */
  5914.  
  5915.       case 'Y' :                                          /* for year search */
  5916.  
  5917.         if ((comp_result = strcmp (base_record->year, s_key_record->year))
  5918.              == 0)               /* if base year and key year are the same - */
  5919.           found = TRUE;                              /* match has been found */
  5920.         break;                                      /* exit switch selection */
  5921.  
  5922.       case 'N' :                                          /* for name search */
  5923.  
  5924.         if ((comp_result = strcmp (base_record->star1, s_key_record->star1))
  5925.                          == 0)            /* if key name matches base star 1 */
  5926.           found = TRUE;                              /* match has been found */
  5927.         if ((comp_result = strcmp (base_record->star2, s_key_record->star1))
  5928.                          == 0)            /* if key name matches base star 2 */
  5929.           found = TRUE;                              /* match has been found */
  5930.         if ((comp_result = strcmp (base_record->star3, s_key_record->star1))
  5931.                          == 0)            /* if key name matches base star 3 */
  5932.           found = TRUE;                              /* match has been found */
  5933.         if ((comp_result = strcmp (base_record->director,
  5934.            s_key_record->star1)) == 0)       /* if key matches base director */
  5935.           found = TRUE;                              /* match has been found */
  5936.         break;                                      /* exit switch selection */
  5937.  
  5938.       case 'S' :                                       /* for subject search */
  5939.  
  5940.         if (base_record->subject == s_key_record->subject) /* if key subject */
  5941.           found = TRUE;        /* same as base subject, match has been found */
  5942.         break;                                      /* exit switch selection */
  5943.  
  5944.       case 'F' :                                          /* for form search */
  5945.       
  5946.         if (base_record->form == s_key_record->form) /* if key form same as  */
  5947.           found = TRUE;                   /* base form, match has been found */
  5948.         break;                                      /* exit switch selection */
  5949.  
  5950.       case 'R' :                                        /* for rating search */
  5951.  
  5952.         if (base_record->rating == s_key_record->rating)    /* if key rating */
  5953.           found = TRUE;         /* same as base rating, match has been found */
  5954.         break;                                      /* exit switch selection */
  5955.  
  5956.       case 'M' :                                        /* for rating search */
  5957.  
  5958.         if (base_record->mpaa_code == s_key_record->mpaa_code)/* if key MPAA */
  5959.           found = TRUE;         /* same as base rating, match has been found */
  5960.         break;                                      /* exit switch selection */
  5961.  
  5962.       default :                                  /* if not valid search code */
  5963.        
  5964.         printf ("**** ERROR - Bad Search Code ****");           /* warn user */
  5965.     }             
  5966.  
  5967.     if (found)                          /* if matching record has been found */
  5968.     {  
  5969.         switch (output_type)       /* select action according to output code */
  5970.         {
  5971.  
  5972.           case 'C' :                        /* for continuous screen display */
  5973.  
  5974.             if (out_count == 0)
  5975.             {
  5976.               sprintf (char_buff,"Search results being displayed on screen...");
  5977.               cbString = (USHORT)strlen(char_buff);
  5978.               VioWrtCharStr(char_buff,cbString,0,0,hvio);
  5979.               VioSetCurPos(23,0,hvio);
  5980.             }
  5981.             disp_rec ((out_count * 5 + 2),base_record);/* display the record */
  5982.             if (++out_count == 4)                          /* if screen full */
  5983.             {
  5984.               time(&time_1);                              /* set time marker */
  5985.               time_2 = time_1 + (long)2;
  5986.               while (time_1 <= time_2)                 /* allow time to read */
  5987.                 time(&time_1);
  5988.               out_count = 0;                                  /* clear count */
  5989.             }          
  5990.             break;                                  /* exit switch selection */
  5991.  
  5992.  
  5993.           case 'S' :                            /* for paused screen display */
  5994.  
  5995.             if (out_count == 0)                    /* if clear screen needed */
  5996.             {
  5997.               clear_screen (WHITE,BLACK);       /* clear screen & set colors */
  5998.               window (0,79,0,0,LGREEN,BLACK);
  5999.               VioSetCurPos (22,0,hvio);
  6000.               sprintf (char_buff,"Search results being displayed on screen...");
  6001.               cbString = (USHORT)strlen(char_buff);
  6002.               VioWrtCharStr(char_buff,cbString,0,0,hvio);
  6003.               
  6004.             }
  6005.             disp_rec ((out_count * 5 + 2),base_record);/* display the record */
  6006.             if (++out_count == 4)                          /* if screen full */
  6007.             {
  6008.               go_ahead = qpause();                          /* wait for user */
  6009.               out_count = 0;                                  /* clear count */
  6010.             }    
  6011.             break;                                  /* exit switch selection */
  6012.  
  6013.  
  6014.           case 'P' :                                   /* for printer output */
  6015.  
  6016.             if (out_count == 0)                        /* if new page needed */
  6017.               fprintf (print_pointer, "\r\f\n");               /* page eject */
  6018.             print_rec (base_record, print_pointer);          /* print record */
  6019.             if (++out_count == 12)                           /* if page full */
  6020.               out_count = 0;                                  /* reset count */
  6021.             else                                                /* otherwise */
  6022.               fprintf (print_pointer, "\n");                  /* skip a line */
  6023.             break;                                  /* exit switch selection */
  6024.  
  6025.         }
  6026.     }         
  6027.   }  
  6028.  
  6029.         /* shutdown after search completed */
  6030.  
  6031.   free ((char *)base_record);            /* free memory allocated to records */
  6032.   free ((char *)s_key_record);
  6033.   free (iobuf);
  6034.   free (char_buff);
  6035.  
  6036.   if (fclose (basef_pointer) != NULL)              /* close base file stream */
  6037.     printf ("\nError in closing base file\n");
  6038.  
  6039.   if (output_type == 'P')                               /* if printer output */
  6040.   {
  6041.     fprintf (print_pointer, "\n\f");                      /* eject last page */
  6042.     if (fclose (print_pointer) == EOF)                       /* close stream */
  6043.        perror ("fclose failed on print_pointer");          /* test for error */
  6044.   }
  6045.  
  6046.   if ((output_type == 'S')||(output_type == 'C'));       /* if screen output */
  6047.   {
  6048.     set_cursor (23,0,0);
  6049.     pause();                                                /* wait for user */
  6050.   }
  6051.   out_count = comp_result;   /* useless instruction to avoid TURBO C warning */
  6052. }
  6053.  
  6054. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ search ^^^^*/
  6055.  
  6056. #pragma subtitle("search_key()")
  6057. #pragma page()
  6058.  
  6059. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv search_key vvvv/*
  6060. /*----------------------------------------------------------------------------+
  6061. |                                                                             |
  6062. | SYNOPSIS                                                                    |
  6063. | ~~~~~~~~                                                                    |
  6064. |   #include stdio.h                                                          |
  6065. |   char search_key(stuct MOVIERECORD s_key_record);                          |
  6066. |                                                                             |
  6067. | FUNCTION                                                                    |
  6068. | ~~~~~~~~                                                                    |
  6069. |   Displays menu of search type choices, gets user choice of search type,    |
  6070. |   obtains appropriate search key data for search type and stores it         |
  6071. |   in s_key_record.                                                          |
  6072. |                                                                             |
  6073. | RETURNS                                                                     |
  6074. | ~~~~~~~                                                                     |
  6075. |   Character code for search type selected by user.                          |
  6076. |                                                                             |
  6077. |                                                                             |
  6078. |                                                                             |
  6079. | NOTES                                                                       |
  6080. | ~~~~~                                                                       |
  6081. |   Calls functions which use nonstandard C extensions; may not be portable   |
  6082. |   accross compilers and operating systems.                                  |
  6083. |                                                                             |
  6084. |                                                                             |
  6085. |                                                                             |
  6086. |                                                                             |
  6087. +----------------------------------------------------------------------------*/
  6088.  
  6089.  
  6090. char search_key (s_key_record)
  6091.  
  6092.   struct MOVIERECORD    *s_key_record;       /* record to contain search key */
  6093.  
  6094.  
  6095. {
  6096.   USHORT                 cbString;                      /* string byte count */
  6097.   char                  *char_buff;                         /* string buffer */
  6098.   extern void            clear_screen();/* func clears screen and sets colors*/
  6099.   extern void            draw_box();             /* func draws box on screen */
  6100.   extern void            get_form();            /* func gets form for record */
  6101.   extern void            get_name();            /* func gets name for record */
  6102.   extern void            get_rating();        /* func gets rating for record */
  6103.   extern void            get_subject();      /* func gets subject for record */
  6104.   extern void            get_title();          /* func gets title for record */
  6105.   extern void            get_year();            /* func gets year for record */
  6106.   HVIO                   hvio = 0;                           /* video handle */
  6107.   char                   response [INPUTLENGTH];/* buffer for keyboard input */
  6108.   char                   s_type;                  /* code for type of search */
  6109.   extern void            set_cursor();          /* func sets cursor position */
  6110.   extern void            trim(); /* func trims leading & trailing whitespace */
  6111.   int                    valid_code = FALSE;  /* boolean flag for valid code */
  6112.   extern void            window();    /* func opens window on screen display */
  6113.                                               /* allocate memory for records */
  6114.   s_type = '\0';                                         /* initialize codes */
  6115.   valid_code = FALSE;
  6116.   char_buff = (char *) calloc (1, 0x100);
  6117.  
  6118.   
  6119.             /* display search menu and get user choice of search type */
  6120.  
  6121.     set_border (BLACK);                                  /* set border color */
  6122.     clear_screen (LWHITE, BLACK);               /* clear screen & set colors */
  6123.     window (10,70,3,19,WHITE,BLUE);
  6124.     draw_box ('l',11,69,3,19);                         /* draw box in window */
  6125.  
  6126.     sprintf (char_buff, "SEARCH MENU");              /* display menu caption */
  6127.     cbString = (USHORT)strlen(char_buff);
  6128.     VioWrtCharStr(char_buff,cbString,5,34,hvio);
  6129.  
  6130.     sprintf (char_buff, "T  =  Title search.");         /* print menu choice */
  6131.     cbString = (USHORT)strlen(char_buff);
  6132.     VioWrtCharStr(char_buff,cbString,9,14,hvio);
  6133.  
  6134.     sprintf (char_buff, "Y  =  Year search.");               /* print choice */
  6135.     cbString = (USHORT)strlen(char_buff);
  6136.     VioWrtCharStr(char_buff,cbString,10,14,hvio);
  6137.  
  6138.     sprintf (char_buff, "N  =  Name search.");               /* print choice */
  6139.     cbString = (USHORT)strlen(char_buff);
  6140.     VioWrtCharStr(char_buff,cbString,11,14,hvio);
  6141.  
  6142.     sprintf (char_buff, "S  =  Subject search.");            /* print choice */
  6143.     cbString = (USHORT)strlen(char_buff);
  6144.     VioWrtCharStr(char_buff,cbString,12,14,hvio);
  6145.  
  6146.     sprintf (char_buff, "F  =  Form search.");               /* print choice */
  6147.     cbString = (USHORT)strlen(char_buff);
  6148.     VioWrtCharStr(char_buff,cbString,13,14,hvio);
  6149.  
  6150.     sprintf (char_buff, "R  =  Rating search. ");            /* print choice */
  6151.     cbString = (USHORT)strlen(char_buff);
  6152.     VioWrtCharStr(char_buff,cbString,14,14,hvio);
  6153.  
  6154.     sprintf (char_buff, "M  =  MPAA code search.");          /* print choice */
  6155.     cbString = (USHORT)strlen(char_buff);
  6156.     VioWrtCharStr(char_buff,cbString,15,14,hvio);
  6157.  
  6158.     sprintf (char_buff, "E  =  Exit to Main Menu.");         /* print choice */
  6159.     cbString = (USHORT)strlen(char_buff);
  6160.     VioWrtCharStr(char_buff,cbString,16,14,hvio);
  6161.  
  6162.  
  6163.   while (!valid_code)                      /* loop until valid code selected */
  6164.   {
  6165.     VioWrtNChar (" ",80,21,0,hvio);
  6166.     sprintf (char_buff,"Enter code -> ");     /* prompt user to enter choice */
  6167.     cbString = (USHORT)strlen(char_buff);
  6168.     VioWrtCharStr(char_buff,cbString,21,10,hvio);
  6169.     VioSetCurPos(21,(10 + cbString),hvio);
  6170.     gets (response);                                    /* get user response */
  6171.     trim (response);                 /* trim leading and trailing whitespace */
  6172.     s_type = toupper (response [0]);    /* get first character in upper case */
  6173.  
  6174.     switch (s_type)                              /* select according to code */
  6175.     {
  6176.       case 'T' :                                                               
  6177.       case 'Y' :
  6178.       case 'N' :
  6179.       case 'S' :                                                               
  6180.       case 'F' :
  6181.       case 'R' :
  6182.       case 'M' :
  6183.       case 'E' :
  6184.  
  6185.         valid_code = TRUE;                    /* set valid code flag to true */
  6186.         break;                                             /* exit selection */
  6187.  
  6188.       default :                                             /* no code match */
  6189.  
  6190.         valid_code = FALSE;   
  6191.         VioSetCurPos(21,10,hvio);                             /* move cursor */
  6192.         printf ("                                                           ");
  6193.         break;
  6194.     }         
  6195.   }
  6196.  
  6197.   clear_screen (LWHITE,BLACK);                /* clear screen & set colors */
  6198.   window (0,79,0,20,LWHITE,BLUE);
  6199.   window (6,78,9,14,BLACK,BLACK);
  6200.   window (4,76,8,13,BLACK,WHITE);
  6201.   set_border (BLUE);                            /* set screen border color */
  6202.   VioSetCurPos (22,0,hvio);                             /* position cursor */
  6203.         
  6204.   switch (s_type)                /* choose action according to search code */
  6205.   {
  6206.     case 'T' :                                         /* for title search */
  6207.  
  6208.  
  6209.       sprintf(char_buff,
  6210.          " The title can be complete or partial.  The search will");
  6211.       cbString = (USHORT)strlen(char_buff);
  6212.       VioWrtCharStr (char_buff,cbString,9,14,hvio);
  6213.       sprintf(char_buff,
  6214.          " report all titles which eactly match the string now   ");
  6215.       cbString = (USHORT)strlen(char_buff);
  6216.       VioWrtCharStr (char_buff,cbString,10,14,hvio);
  6217.       sprintf(char_buff,
  6218.          " entered or which contain the string now entered as a  ");
  6219.       cbString = (USHORT)strlen(char_buff);
  6220.       VioWrtCharStr (char_buff,cbString,11,14,hvio);
  6221.       sprintf(char_buff,
  6222.          " a substring.                                          ");
  6223.       cbString = (USHORT)strlen(char_buff);
  6224.       VioWrtCharStr (char_buff,cbString,12,14,hvio);
  6225.       pause();
  6226.       VioWrtNChar(" ",80,22,0,hvio);
  6227.       VioWrtNChar(" ",80,23,0,hvio);
  6228.       VioWrtNChar(" ",80,24,0,hvio);
  6229.       VioSetCurPos(22,0,hvio);
  6230.  
  6231.       get_title (s_key_record->title);          /* get full or partial title */
  6232.       trim (s_key_record->title);                              /* trim title */
  6233.       valid_code = TRUE;                      /* set valid code flag to true */
  6234.       break;                                                    /* exit loop */
  6235.                                      /* note: title must be trimmed to avoid */
  6236.                                      /* blank padding which would prevent    */
  6237.                                      /* substring match for partial title    */
  6238.  
  6239.       case 'Y' :                                          /* for year search */
  6240.  
  6241.         get_year (s_key_record->year);                           /* get year */
  6242.         valid_code = TRUE;                    /* set valid code flag to true */
  6243.         break;                                                  /* exit loop */
  6244.  
  6245.       case 'N' :                                          /* for name search */
  6246.  
  6247.         get_name (s_key_record->star1, "Name");                  /* get name */
  6248.         valid_code = TRUE;                    /* set valid code flag to true */
  6249.         break;                                                  /* exit loop */
  6250.                                     /* note: the star1 field is arbitrarily  */
  6251.                                     /* used to hold the search key name; it  */
  6252.                                     /* will actually be matched against all  */
  6253.                                     /* name fields in each base record.      */
  6254.                                     
  6255.       case 'S' :                                       /* for subject search */
  6256.       
  6257.         get_subject (&s_key_record->subject);                 /* get subject */
  6258.         valid_code = TRUE;                    /* set valid code flag to true */
  6259.         break;                                                  /* exit loop */
  6260.  
  6261.       case 'F' :                                          /* for form search */
  6262.  
  6263.         get_form (&s_key_record->form);                          /* get form */
  6264.         valid_code = TRUE;                    /* set valid code flag to true */
  6265.         break;                                                  /* exit loop */
  6266.  
  6267.       case 'R' :                                        /* for rating search */
  6268.  
  6269.         get_rating (&s_key_record->rating);                    /* get Rating */
  6270.         valid_code = TRUE;                    /* set valid code flag to true */
  6271.         break;                                                  /* exit loop */
  6272.  
  6273.       case 'M' :                                        /* for rating search */
  6274.  
  6275.         get_mpaa_code (&s_key_record->mpaa_code);           /* get MPAA code */
  6276.         valid_code = TRUE;                    /* set valid code flag to true */
  6277.         break;                                                  /* exit loop */
  6278.  
  6279.       case 'E' :                                         /* for exit request */
  6280.     
  6281.         return (s_type);     /* exit from function and return to main module */
  6282.  
  6283.       default :                                             /* no code match */
  6284.  
  6285.         valid_code = FALSE;                  /* set valid code flag to false */
  6286.         printf ("\nINVALID CODE\n");      /* warn user invalid code selected */
  6287.         pause();                                            /* wait for user */
  6288.     }
  6289.   free (char_buff);
  6290.   return (s_type);
  6291. }
  6292.  
  6293. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ search_key ^^^^*/
  6294.  
  6295. #pragma subtitle("set_border()")
  6296. #pragma page()
  6297.  
  6298. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv set_border   vvvv*/
  6299.  
  6300. /*----------------------------------------------------------------------------+
  6301. |                                                                             |
  6302. | SYNOPSIS                                                                    |
  6303. | ~~~~~~~~                                                                    |
  6304. |   #include <dos.h>                                                          |
  6305. |   void set_border (int color)                                               |
  6306. |                                                                             |
  6307. | FUNCTION                                                                    |
  6308. | ~~~~~~~~                                                                    |
  6309. |   Sets the screen border to the color ID.                                   |
  6310. |                                                                             |
  6311. |                                                                             |
  6312. | RETURNS                                                                     |
  6313. | ~~~~~~~                                                                     |
  6314. |   Nothing.                                                                  |
  6315. |                                                                             |
  6316. |                                                                             |
  6317. |                                                                             |
  6318. | NOTES                                                                       |
  6319. | ~~~~~                                                                       |
  6320. |   Uses VioSetState to set the overscan.  According to the OS/2              |
  6321. |   Programmer's Toolkit Reference, this is not a family API function;        |
  6322. |   however it seems to work properly.  May not be portable accross           |
  6323. |   compilers and operating systems.                                          |
  6324. |                                                                             |
  6325. +----------------------------------------------------------------------------*/
  6326.  
  6327. void set_border (color)                                  /* set border color */
  6328.  
  6329.   int color;                                    /* color ID for border color */
  6330.     
  6331. {
  6332.  
  6333.   extern int         has_color();
  6334.   VIOOVERSCAN        vio_overscan;
  6335.   HVIO                hvio = 0;
  6336.  
  6337.   if (has_color())
  6338.   {
  6339.    vio_overscan.cb = (USHORT)sizeof(struct _VIOOVERSCAN);
  6340.    vio_overscan.type = 0x0001;
  6341.    vio_overscan.color = color;
  6342.    VioSetState (&vio_overscan, hvio);
  6343.   }  
  6344. }
  6345.  
  6346. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ set_border   ^^^^*/
  6347.  
  6348. #pragma subtitle("set_cursor()")
  6349. #pragma page()
  6350.  
  6351. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv set_cursor   vvvv*/
  6352.  
  6353. /*----------------------------------------------------------------------------+
  6354. |                                                                             |
  6355. | SYNOPSIS                                                                    |
  6356. | ~~~~~~~~                                                                    |
  6357. |   #include <dos.h>                                                          |
  6358. |   void set_cursor (int row, column, page)                                   |
  6359. |                                                                             |
  6360. | FUNCTION                                                                    |
  6361. | ~~~~~~~~                                                                    |
  6362. |   Sets cursor to position at the specified row and column on the            |
  6363. |   specified video page.                                                     |
  6364. |                                                                             |
  6365. |                                                                             |
  6366. | RETURNS                                                                     |
  6367. | ~~~~~~~                                                                     |
  6368. |   Nothing.                                                                  |
  6369. |                                                                             |
  6370. |                                                                             |
  6371. |                                                                             |
  6372. | NOTES                                                                       |
  6373. | ~~~~~                                                                       |
  6374. |   The page value is an artifact from a prior version which used             |
  6375. |   a DOS interrupt.  It no longer serves any function.  Eventually           |
  6376. |   all calls to this function will be replaced with VioSetCurPos             |
  6377. |   and it will be eliminated.                                                |
  6378. |                                                                             |
  6379. +----------------------------------------------------------------------------*/
  6380.  
  6381. void set_cursor (row, column, page)                   /* set cursor position */
  6382.  
  6383.   int               row, column, page;
  6384.  
  6385. {
  6386.   HVIO    hvio = 0;
  6387.   page = page;  
  6388.   VioSetCurPos (row, column, hvio);
  6389.  
  6390. }
  6391.  
  6392. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ set_cursor   ^^^^*/
  6393.  
  6394. #pragma subtitle("tally ()")
  6395. #pragma page()
  6396.  
  6397. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv tally vvvv*/
  6398.  
  6399. /*----------------------------------------------------------------------------+
  6400. |                                                                             |
  6401. | SYNOPSIS                                                                    |
  6402. | ~~~~~~~~                                                                    |
  6403. |   #include <stdio.h>                                                        |
  6404. |   #include <string.h>                                                       |
  6405. |   void tally(char *base_file_id)                                            |
  6406. |                                                                             |
  6407. | FUNCTION                                                                    |
  6408. | ~~~~~~~~                                                                    |
  6409. |   Reads all records in base_file_id, keeping tallies by the subject,        |
  6410. |   form, and rating code for each record.  The function tally_sort()         |
  6411. |   is called to sort each tally into descending order.  Then a report        |
  6412. |   is displayed for each catagory, showing the number of occurrences         |
  6413. |   and percentage distribution.                                              |
  6414. |                                                                             |
  6415. | RETURNS                                                                     |
  6416. | ~~~~~~~                                                                     |
  6417. |   Nothing.                                                                  |
  6418. |                                                                             |
  6419. |                                                                             |
  6420. | NOTES                                                                       |
  6421. | ~~~~~                                                                       |
  6422. |   Uses only ANSI standard functions and should be portable.                 |
  6423. |                                                                             |
  6424. |                                                                             |
  6425. +----------------------------------------------------------------------------*/
  6426.  
  6427. void tally(base_file_id)                   /* tally statistics for data base */
  6428.  
  6429. char *base_file_id;                /* string path and file name of base file */
  6430.  
  6431. {
  6432.  
  6433.   FILE                  *basef_pointer;              /* pointer to base file */
  6434.   struct MOVIERECORD    *base_record;      /* buffer to hold one base record */
  6435.   USHORT                 cbString;                      /* string byte count */
  6436.   char                  *char_buff;                         /* string buffer */
  6437.   extern void            clear_screen(); /* func clears screen & sets colors */
  6438.   int                    count;                                  /* counters */
  6439.   struct NAMERECORD far *dir_name_list = NULL;         /* director name list */
  6440.   char                   form_codes[FORMNUMBER];/* local array of form codes */
  6441.   int                    form_counts [FORMNUMBER];   /* array of form counts */
  6442.   HVIO                   hvio = 0;                           /* video handle */
  6443.   char                  *iobuf;                       /* buffer for file i/o */
  6444.   struct NAMERECORD far *name_ptr = NULL;            /* pointer to name list */
  6445.   char                   rating_codes[RATINGNUMBER]; /* local array of codes */
  6446.   int                    rating_counts [RATINGNUMBER];/* array of rate counts*/
  6447.   struct NAMERECORD far *star_name_list = NULL;           /* actor name list */
  6448.   char                   subj_codes[SUBJNUMBER];/* local array of subj codes */
  6449.   int                    subj_counts [SUBJNUMBER];/* array of subject counts */
  6450.   extern void            tally_display();   /* func displays result of tally */
  6451.   struct YEARRECORD far *tally_list_year();  /* func bulids linked year list */
  6452.   int                    total_movies = 0;/* total number of records in base */
  6453.   struct YEARRECORD far *year_list = NULL;               /* year linked list */
  6454.   struct YEARRECORD far *year_ptr = NULL;            /* pointer to year list */
  6455.   int test_count = 0;
  6456.  
  6457.  
  6458.   clear_screen (MAGENTA, BLACK);
  6459.   VioSetCurPos (23, 0, hvio);
  6460.   char_buff = (char *) calloc (1, 0x100);
  6461.  
  6462.     /* initialize local arrays */
  6463.  
  6464.   for (count = 0; count < SUBJNUMBER; count++)      /* for each subject code */
  6465.   {
  6466.     subj_codes [count] = codes [count];        /* get code from global array */
  6467.     subj_counts [count] = 0;                         /* initialize count = 0 */
  6468.   }
  6469.   for (count = 0; count < FORMNUMBER; count++)         /* for each form code */
  6470.   {
  6471.     form_codes [count] = codes [count];        /* get code from global array */
  6472.     form_counts [count] = 0;                         /* initialize count = 0 */
  6473.   }
  6474.   for (count = 0; count < RATINGNUMBER; count++)
  6475.   {
  6476.     rating_codes [count] = codes [count];      /* get code from global array */
  6477.     rating_counts [count] = 0;                       /* initialize count = 0 */
  6478.   }
  6479.  
  6480.   iobuf = calloc (1, BIGBUFF);        /* allocate memory for file i/o buffer */
  6481.   if ((basef_pointer = fopen (base_file_id, "rb")) == NULL)    /* open basef */
  6482.   {                                                       /* if open error - */
  6483.     printf ("\Unable to open base file\n");                     /* warn user */
  6484.     pause();                                                /* wait for user */
  6485.     fcloseall();                                          /* close all files */
  6486.     return;                                                         /* abort */
  6487.   }
  6488.   setvbuf (basef_pointer, iobuf,_IOFBF, BIGBUFF); /* big buffer for file i/o */
  6489.  
  6490.   base_record = (struct MOVIERECORD *)calloc (1, sizeof (struct MOVIERECORD));
  6491.                                     /* allocate memory to base record buffer */
  6492.   total_movies = 0;                           /* initialize record count = 0 */
  6493.  
  6494.   while (!(feof (basef_pointer)))                 /* while not EOF base file */
  6495.     {
  6496.       if ((fread ((char *)base_record, sizeof (struct MOVIERECORD),
  6497.            1, basef_pointer)) != 1)      /* read a record from the base file */
  6498.       {                                                   /* if read error - */
  6499.         if (!(feof(basef_pointer)))   /* - and not end of file (normal term) */
  6500.         {
  6501.            printf ("\nError in reading base file\n");           /* warn user */
  6502.            pause();                                         /* wait for user */
  6503.            fcloseall();                                   /* close all files */
  6504.            return;                                                  /* abort */
  6505.         }
  6506.         else break;             /* otherwise (normal) exit loop and continue */
  6507.       }
  6508.  
  6509.       total_movies++;                            /* increment record counter */
  6510.  
  6511.       sprintf (char_buff, "Analyzing: %4d  %s",
  6512.                total_movies, base_record->title);
  6513.       cbString = (USHORT)strlen(char_buff);
  6514.       VioWrtCharStr (char_buff, cbString, 10, 10, hvio);
  6515.  
  6516.       for (count = 0; count < SUBJNUMBER; count++)     /* check subject code */
  6517.         if (base_record->subject == subj_codes [count])     /* and increment */
  6518.           (subj_counts [count])++;                    /* corresponding count */
  6519.  
  6520.       for (count = 0; count < FORMNUMBER; count++)        /* check form code */
  6521.         if (base_record->form == form_codes [count])        /* and increment */
  6522.           (form_counts [count])++;                    /* corresponding count */
  6523.  
  6524.       for (count = 0; count < RATINGNUMBER; count++)    /* check rating code */
  6525.         if (base_record->rating == rating_codes [count])    /* and increment */
  6526.           (rating_counts [count])++;                  /* corresponding count */
  6527.  
  6528.       dir_name_list = tally_list_name (base_record->director, dir_name_list);
  6529.        star_name_list = tally_list_name (base_record->star1, star_name_list);
  6530.        star_name_list = tally_list_name (base_record->star2, star_name_list);
  6531.        star_name_list = tally_list_name (base_record->star3, star_name_list);
  6532.        year_list = tally_list_year (base_record->year, year_list);
  6533.  
  6534.       if (test_count++ >= MAXRECORDS)
  6535.         break;
  6536.     }
  6537.   tally_display ( dir_name_list, star_name_list, year_list,
  6538.                   form_codes, form_counts, rating_codes, rating_counts,
  6539.                      subj_codes, subj_counts, total_movies);
  6540.  
  6541.  
  6542.     while (dir_name_list != NULL)
  6543.     {
  6544.       name_ptr = dir_name_list;
  6545.       dir_name_list = dir_name_list->next_name_rec;
  6546.       DosFreeSeg (name_ptr->sel);
  6547.     }
  6548.  
  6549.     while (star_name_list != NULL)
  6550.     {
  6551.       name_ptr = star_name_list;
  6552.       star_name_list = star_name_list->next_name_rec;
  6553.       DosFreeSeg (name_ptr->sel);
  6554.     }
  6555.             
  6556.     while (year_list != NULL)
  6557.     {
  6558.       year_ptr = year_list;
  6559.       year_list = year_list->next_year_rec;
  6560.       DosFreeSeg (year_ptr->sel);
  6561.     }
  6562.  
  6563.   free ((char *)base_record);        /* free memory allocated to base record */
  6564.   if (fclose (basef_pointer) != NULL)         /* close base file - if error, */
  6565.     printf ("\nError in closing base file\n");                  /* warn user */
  6566.   free (iobuf);                  /* free memory allocated to file i/o buffer */
  6567.   free (char_buff);
  6568. }    
  6569.  
  6570. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ tally ^^^^*/
  6571.  
  6572. #pragma subtitle("tally_display ()")
  6573. #pragma page()
  6574.  
  6575. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv tally_display vvvv*/
  6576.  
  6577. /*----------------------------------------------------------------------------+
  6578. |                                                                             |
  6579. | SYNOPSIS                                                                    |
  6580. | ~~~~~~~~                                                                    |
  6581. |   #include <stdio.h>                                                        |
  6582. |   #include <string.h>                                                       |
  6583. |   void tally_display (char form_codes[], int form_counts[],                 |
  6584. |                        char rating_codes[], int rating_counts[],            |
  6585. |                        char subj_codes[], int subj_counts[],                |
  6586. |                        int total_movies)                                    |
  6587. |                                                                             |
  6588. |                                                                             |
  6589. |                                                                             |
  6590. | FUNCTION                                                                    |
  6591. | ~~~~~~~~                                                                    |
  6592. |                                                                             |
  6593. |   Prints a display of the statistics recorded in the arrays for form        |
  6594. |   codes, form counts, subject codes, subject counts, rating codes, and      |
  6595. |   rating counts, using total movies count to calculate percentages.         |
  6596. |   Displays top of actor, director and year frequency lists.                 |
  6597. |                                                                             |
  6598. | RETURNS                                                                     |
  6599. | ~~~~~~~                                                                     |
  6600. |                                                                             |
  6601. |   Nothing.                                                                  |
  6602. |                                                                             |
  6603. | NOTES                                                                       |
  6604. | ~~~~~                                                                       |
  6605. |   Calls functions which use nonstandard C extensions; may not be            |
  6606. |   portable accross compilers and operating systems.                         |
  6607. |                                                                             |
  6608. |                                                                             |
  6609. +----------------------------------------------------------------------------*/
  6610.  
  6611. void tally_display (dir_name_list, star_name_list, year_list,
  6612.                      form_codes, form_counts, rating_codes, rating_counts,
  6613.                      subj_codes, subj_counts, total_movies)
  6614.  
  6615.   struct NAMERECORD far *dir_name_list;                /* director name list */
  6616.   struct NAMERECORD far *star_name_list;                  /* actor name list */
  6617.   struct YEARRECORD far *year_list;                      /* year linked list */
  6618.   char                  form_codes[];           /* local array of form codes */
  6619.   int                   form_counts[];               /* array of form counts */
  6620.   char                  rating_codes[];              /* local array of codes */
  6621.   int                   rating_counts [];             /* array of rate counts*/
  6622.   char                  subj_codes[];           /* local array of subj codes */
  6623.   int                   subj_counts[];            /* array of subject counts */
  6624.   int                   total_movies;     /* total number of records in base */
  6625.  
  6626. {
  6627.  
  6628.   USHORT                cbString;                       /* string byte count */
  6629.   char                 *char_buff;                          /* string buffer */
  6630.   extern void           clear_screen();  /* func clears screen & sets colors */
  6631.   int                   count;                                    /* counter */
  6632.   int                   i, j;                                    /* counters */
  6633.   double                fhundred = 100.0;                  /* constant 100.0 */
  6634.   char                  go_ahead = ' ';                       /* quit signal */
  6635.   HVIO                  hvio = 0;                            /* video handle */
  6636.   struct NAMERECORD far *name_ptr = NULL;            /* pointer to name list */
  6637.   extern void           name_out();    /* func coverts name form for display */
  6638.   double                percent1, percent2;        /* percentages calculated */
  6639.   extern char           qpause();         /* func asks if user wants to quit */
  6640.   extern void           tally_sort();                 /* func to sort arrays */
  6641.   char                  text1[INPUTLENGTH];     /* text descriptor for table */
  6642.   char                  text2[INPUTLENGTH];     /* text descriptor for table */
  6643.   struct YEARRECORD far *year_ptr = NULL;            /* pointer to year list */
  6644.   extern void           window();                       /* func opens window */
  6645.    
  6646.  
  6647.    
  6648.   
  6649.             /* prepare and display analysis by subject code */
  6650.             
  6651.   char_buff = (char *) calloc (1, 0x100);
  6652.   clear_screen (BLACK, WHITE);
  6653.   window (0,79,23,24,WHITE,BLACK);
  6654.   VioSetCurPos(23,0,hvio);
  6655.   sprintf (char_buff,"                               Subject Analysis");
  6656.   cbString = (USHORT)strlen(char_buff);
  6657.   VioWrtCharStr (char_buff,cbString,0,0,hvio);
  6658.   tally_sort (SUBJNUMBER, subj_codes, subj_counts);
  6659.   for (i = 0; i < (int)(SUBJNUMBER/2); i++)
  6660.   {
  6661.     for (j = 0; j < SUBJNUMBER; j++)
  6662.     {
  6663.       if (subj_codes [i] == codes[j])
  6664.         strcpy (text1, subjects[j]);
  6665.       if (subj_codes [i + (int)(SUBJNUMBER/2)] == codes[j])
  6666.         strcpy (text2, subjects[j]);
  6667.     }
  6668.     percent1 = (double)subj_counts[i] / (double)total_movies;
  6669.     percent1 = percent1 * fhundred;
  6670.     percent2 =
  6671.            (double)subj_counts[i + (int)(SUBJNUMBER/2)] /(double)total_movies;
  6672.     percent2 = percent2 * fhundred;
  6673.     sprintf (char_buff,"    %6d %s  %5.2f%%     \x0B3  %6d %s  %5.2f%%",
  6674.             subj_counts [i],
  6675.             text1,
  6676.             percent1,      
  6677.             subj_counts [i + ((int)(SUBJNUMBER/2))],
  6678.             text2,
  6679.             percent2);
  6680.     cbString = (USHORT)strlen(char_buff);
  6681.     VioWrtCharStr (char_buff,cbString,(i +2),0,hvio);
  6682.   }
  6683.   pause();
  6684.             /* prepare and display analysis by form code */
  6685.  
  6686.   clear_screen (BLACK, WHITE);
  6687.   window (0,79,23,24,WHITE,BLACK);
  6688.   VioSetCurPos(23,0,hvio);
  6689.   sprintf (char_buff,"                                  Form Analysis");
  6690.   cbString = (USHORT)strlen(char_buff);
  6691.   VioWrtCharStr (char_buff,cbString,2,0,hvio);
  6692.   tally_sort (FORMNUMBER, form_codes, form_counts);
  6693.   for (i = 0; i < (int)(FORMNUMBER/2); i++)
  6694.   {
  6695.     for (j = 0; j < FORMNUMBER; j++)
  6696.     {
  6697.       if (form_codes [i] == codes[j])
  6698.         strcpy (text1, forms[j]);
  6699.       if (form_codes [i + (int)(FORMNUMBER/2)] == codes[j])
  6700.         strcpy (text2, forms[j]);
  6701.     }
  6702.     percent1 = (double)form_counts[i] / (double)total_movies;
  6703.     percent1 = percent1 * fhundred;
  6704.     percent2 =
  6705.            (double)form_counts[i + (int)(FORMNUMBER/2)] /(double)total_movies;
  6706.     percent2 = percent2 * fhundred;
  6707.     sprintf (char_buff,"    %6d %s  %5.2f%%     \x0B3  %6d %s  %5.2f%%",
  6708.             form_counts [i],
  6709.             text1,
  6710.             percent1,      
  6711.             form_counts [i + ((int)(FORMNUMBER/2))],
  6712.             text2,
  6713.             percent2);
  6714.     cbString = (USHORT)strlen(char_buff);
  6715.     VioWrtCharStr (char_buff,cbString,(i + 4),0,hvio);
  6716.   }
  6717.   pause();
  6718.  
  6719.             /* prepare and display analysis by rating code */
  6720.  
  6721.  
  6722.   clear_screen (BLACK, WHITE);
  6723.   window (0,79,23,24,WHITE,BLACK);
  6724.   VioSetCurPos(23,0,hvio);
  6725.   sprintf (char_buff,"                               Rating Analysis");
  6726.   cbString = (USHORT)strlen(char_buff);
  6727.   VioWrtCharStr (char_buff,cbString,5,0,hvio);
  6728.   tally_sort (RATINGNUMBER, rating_codes, rating_counts);
  6729.   for (i = 0; i < (int)(RATINGNUMBER/2); i++)
  6730.   {
  6731.     for (j = 0; j < RATINGNUMBER; j++)
  6732.     {
  6733.       if (rating_codes [i] == codes[j])
  6734.         strcpy (text1, ratings[j]);
  6735.       if (rating_codes [i + (int)(RATINGNUMBER/2)] == codes[j])
  6736.         strcpy (text2, ratings[j]);
  6737.     }
  6738.     percent1 = (double)rating_counts[i] / (double)total_movies;
  6739.     percent1 = percent1 * fhundred;
  6740.     percent2 =
  6741.            (double)rating_counts[i +
  6742.               (int)(RATINGNUMBER/2)] /(double)total_movies;
  6743.     percent2 = percent2 * fhundred;
  6744.     sprintf (char_buff, "    %6d %s  %5.2f%%     \x0B3  %6d %s  %5.2f%%",
  6745.             rating_counts [i],
  6746.             text1,
  6747.             percent1,      
  6748.             rating_counts [i + ((int)(RATINGNUMBER/2))],
  6749.             text2,
  6750.             percent2);
  6751.     cbString = (USHORT)strlen(char_buff);
  6752.     VioWrtCharStr (char_buff,cbString,(i + 7),0,hvio);
  6753.   }
  6754.   sprintf (char_buff,"          Total number = %d", total_movies);
  6755.   cbString = (USHORT)strlen(char_buff);
  6756.   VioWrtCharStr (char_buff,cbString,20,0,hvio);
  6757.   pause();
  6758.  
  6759.                /* display actor name list */
  6760.  
  6761.   name_ptr = star_name_list;
  6762.   go_ahead = 'Y';
  6763.  
  6764.   while ((name_ptr != NULL) && (go_ahead != 'Q'))
  6765.   {
  6766.     clear_screen (BLACK, WHITE);
  6767.     window (0,79,23,24,WHITE,BLACK);
  6768.     sprintf (char_buff, "Actor Name Frequency Analysis");
  6769.     cbString = (USHORT)strlen(char_buff);
  6770.     VioWrtCharStr (char_buff, cbString, 1,22, hvio);
  6771.     VioSetCurPos (24,0,hvio);
  6772.     for (count = 0; count < 20; count++)
  6773.       {
  6774.         if (name_ptr == NULL)
  6775.            break;
  6776.         name_out (name_ptr->name);
  6777.         sprintf (char_buff,"%4d  %s", name_ptr->count,name_ptr->name);
  6778.         cbString = (USHORT)strlen(char_buff);
  6779.         VioWrtCharStr (char_buff, cbString, (3 + count), 0, hvio);
  6780.         name_ptr = name_ptr->next_name_rec;
  6781.       }
  6782.     for (count = 0; count < 20; count++)
  6783.       {
  6784.         if (name_ptr == NULL)
  6785.            break;
  6786.         name_out (name_ptr->name);
  6787.         sprintf (char_buff,"\x0B3 %4d  %s", name_ptr->count,name_ptr->name);
  6788.         cbString = (USHORT)strlen(char_buff);
  6789.         VioWrtCharStr (char_buff, cbString, (3 + count), 39, hvio);
  6790.         name_ptr = name_ptr->next_name_rec;
  6791.       }
  6792.     go_ahead = qpause();
  6793.   }
  6794.  
  6795.                /* Display director name list */
  6796.  
  6797.   name_ptr = dir_name_list;
  6798.   go_ahead = 'Y';
  6799.  
  6800.   while ((name_ptr != NULL) && (go_ahead != 'Q'))
  6801.   {
  6802.     clear_screen (BLACK, WHITE);
  6803.     window (0,79,23,24,WHITE,BLACK);
  6804.     sprintf (char_buff, "Director Name Frequency Analysis");
  6805.     cbString = (USHORT)strlen(char_buff);
  6806.     VioWrtCharStr (char_buff, cbString, 1,22, hvio);
  6807.     VioSetCurPos (24,0,hvio);
  6808.     for (count = 0; count < 20; count++)
  6809.       {
  6810.         if (name_ptr == NULL)
  6811.            break;
  6812.         name_out (name_ptr->name);
  6813.         sprintf (char_buff,"%4d  %s", name_ptr->count,name_ptr->name);
  6814.         cbString = (USHORT)strlen(char_buff);
  6815.         VioWrtCharStr (char_buff, cbString, (3 + count), 0, hvio);
  6816.         name_ptr = name_ptr->next_name_rec;
  6817.       }
  6818.     for (count = 0; count < 20; count++)
  6819.       {
  6820.         if (name_ptr == NULL)
  6821.            break;
  6822.         name_out (name_ptr->name);
  6823.         sprintf (char_buff,"\x0B3 %4d  %s", name_ptr->count,name_ptr->name);
  6824.         cbString = (USHORT)strlen(char_buff);
  6825.         VioWrtCharStr (char_buff, cbString, (3 + count), 39, hvio);
  6826.         name_ptr = name_ptr->next_name_rec;
  6827.       }
  6828.     go_ahead = qpause();
  6829.   }
  6830.  
  6831.                /* Display Year List */
  6832.  
  6833.  
  6834.   clear_screen (BLACK, WHITE);
  6835.   window (0,79,23,24,WHITE,BLACK);
  6836.   sprintf (char_buff, "Year of Release Frequency Analysis");
  6837.   cbString = (USHORT)strlen(char_buff);
  6838.   VioWrtCharStr (char_buff, cbString, 1,22, hvio);
  6839.   VioSetCurPos (23,0,hvio);
  6840.   year_ptr = year_list;
  6841.   for (count = 0; count < 20; count++)
  6842.       {
  6843.         if (year_ptr == NULL)
  6844.            break;
  6845.         sprintf (char_buff,"\x0B3 %4d  %s \x0B3",
  6846.            year_ptr->count,year_ptr->year);
  6847.         cbString = (USHORT)strlen(char_buff);
  6848.         VioWrtCharStr (char_buff, cbString, (3 + count), 0, hvio);
  6849.         year_ptr = year_ptr->next_year_rec;
  6850.       }
  6851.   for (count = 0; count < 20; count++)
  6852.       {
  6853.         if (year_ptr == NULL)
  6854.            break;
  6855.         sprintf (char_buff,"\x0B3 %4d  %s \x0B3",
  6856.            year_ptr->count,year_ptr->year);
  6857.         cbString = (USHORT)strlen(char_buff);
  6858.         VioWrtCharStr (char_buff, cbString, (3 + count), 16, hvio);
  6859.         year_ptr = year_ptr->next_year_rec;
  6860.       }
  6861.   for (count = 0; count < 20; count++)
  6862.       {
  6863.         if (year_ptr == NULL)
  6864.            break;
  6865.         sprintf (char_buff,"\x0B3 %4d  %s \x0B3",
  6866.            year_ptr->count,year_ptr->year);
  6867.         cbString = (USHORT)strlen(char_buff);
  6868.         VioWrtCharStr (char_buff, cbString, (3 + count), 32, hvio);
  6869.         year_ptr = year_ptr->next_year_rec;
  6870.       }
  6871.   for (count = 0; count < 20; count++)
  6872.       {
  6873.         if (year_ptr == NULL)
  6874.            break;
  6875.         sprintf (char_buff,"\x0B3 %4d  %s \x0B3",
  6876.            year_ptr->count,year_ptr->year);
  6877.         cbString = (USHORT)strlen(char_buff);
  6878.         VioWrtCharStr (char_buff, cbString, (3 + count), 48, hvio);
  6879.         year_ptr = year_ptr->next_year_rec;
  6880.       }
  6881.   for (count = 0; count < 20; count++)
  6882.       {
  6883.         if (year_ptr == NULL)
  6884.            break;
  6885.         sprintf (char_buff,"\x0B3 %4d  %s \x0B3",
  6886.            year_ptr->count,year_ptr->year);
  6887.         cbString = (USHORT)strlen(char_buff);
  6888.         VioWrtCharStr (char_buff, cbString, (3 + count), 64, hvio);
  6889.         year_ptr = year_ptr->next_year_rec;
  6890.       }
  6891.  
  6892.   pause();
  6893.   free (char_buff);
  6894. }    
  6895.  
  6896. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ tally_display ^^^^*/
  6897.  
  6898. #pragma subtitle("tally_list_name ()")
  6899. #pragma page()
  6900.  
  6901. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv tally_list_name vvvv*/
  6902.  
  6903. /*----------------------------------------------------------------------------+
  6904. |                                                                             |
  6905. | SYNOPSIS                                                                    |
  6906. | ~~~~~~~~                                                                    |
  6907. |   #include <os2.h>                                                          |
  6908. |   #include <stdio.h>                                                        |
  6909. |   #include <string.h>                                                       |
  6910. |   void tally_list_name (char *new_name, struct NAMERECORD far *name_list)   |
  6911. |                                                                             |
  6912. | FUNCTION                                                                    |
  6913. | ~~~~~~~~                                                                    |
  6914. |   Creates a name list if not previously created.  Compares new_name to      |
  6915. |   each cell in the list until a name match is found or the end of the       |
  6916. |   list is reached.  If a match is found, the count is incremetned.  If      |
  6917. |   no match is found, a new cell is added with the new name.  The cell       |
  6918. |   for the new name is bubbled up the list to maintain frequency order.      |
  6919. |                                                                             |
  6920. | RETURNS                                                                     |
  6921. | ~~~~~~~                                                                     |
  6922. |   Pointer to head of doubly-linked name list.                               |
  6923. |                                                                             |
  6924. |                                                                             |
  6925. | NOTES                                                                       |
  6926. | ~~~~~                                                                       |
  6927. |   Uses MSC extenstions and may not be portable.                             |
  6928. |                                                                             |
  6929. |                                                                             |
  6930. +----------------------------------------------------------------------------*/
  6931.  
  6932. struct NAMERECORD far *tally_list_name (new_name, name_list)
  6933.   char *new_name;                                     /* pointer to new name */
  6934.   struct NAMERECORD far *name_list;          /* pointer to head of name list */
  6935.   
  6936. {
  6937.   USHORT                   cbString;                    /* string byte count */
  6938.   char                    *char_buff;                       /* string buffer */
  6939.   HVIO                     hvio = 0;                         /* video handle */
  6940.   static int               out_of_memory = FALSE;      /* out of memory flag */    
  6941.   SEL                      sel;                     /* memory block selector */
  6942.   struct NAMERECORD far   *temp_current;       /* ptr to current name record */
  6943.   struct NAMERECORD far   *temp_next;             /* ptr to next name record */
  6944.   struct NAMERECORD        temp_rec;                /* temporary name record */
  6945.   
  6946.   if (new_name[0] == ',')                      /* if no new name, do nothing */
  6947.     return name_list;                               /* return list unchanged */
  6948.  
  6949.    
  6950.        /* if no list, establsh one */
  6951.  
  6952.   if (name_list == NULL)        /* if no memory yet allocated to name list - */
  6953.     {
  6954.       out_of_memory = DosAllocSeg ((sizeof (struct NAMERECORD)), &sel, 0);
  6955.       if (out_of_memory)       /* allocate memory and test for out of memory */
  6956.         return name_list;
  6957.       name_list = MAKEP (sel, 0);      /* make a pointer out of the selector */
  6958.       strcpy (name_list->name, new_name);           /* copy name to the list */
  6959.       name_list->count = 1;                                 /* set count = 1 */
  6960.       name_list->sel = sel;                           /* record the selector */
  6961.       name_list->last_name_rec = NULL;              /* set back link to null */
  6962.       name_list->next_name_rec = NULL;           /* set forward link to null */
  6963.          return name_list;                             /* return the pointer */
  6964.     }
  6965.  
  6966.       /* move down list until name match or end of list */
  6967.  
  6968.   temp_current = name_list;               /* set current ptr to head of list */
  6969.   while ((temp_current->next_name_rec != NULL)    /* while not end of list - */
  6970.      && (strcmp (temp_current->name, new_name)))       /* and no name match - */
  6971.     {
  6972.     temp_current = temp_current->next_name_rec;          /* move to next link */
  6973.     }
  6974.  
  6975.       /* if match found, increment count */
  6976.       /* if no match, then add new cell to list */
  6977.  
  6978.   if ((strcmp (temp_current->name, new_name)) == 0)       /* if name match - */
  6979.     temp_current->count = temp_current->count + 1;        /* increment count */
  6980.   else                                                        /* otherwise - */
  6981.     if (! (out_of_memory))                           /* if not out of memory */
  6982.     {
  6983.       out_of_memory = DosAllocSeg ((sizeof (struct NAMERECORD)), &sel, 0);
  6984.       if (out_of_memory)          /* allocate memory for new cell and test - */
  6985.       {
  6986.         char_buff = (char *) calloc (1, 0x100);
  6987.         sprintf (char_buff, "All available memory in use.");
  6988.         cbString = (USHORT)strlen(char_buff);
  6989.         VioWrtCharStr (char_buff,cbString,20,5,hvio);
  6990.         free (char_buff);
  6991.         return name_list;    /* return unchanged if memory allocation failed */
  6992.       }
  6993.       temp_next = MAKEP (sel, 0);        /* make a pointer from the selector */
  6994.       strcpy (temp_next->name, new_name); /* copy the new name into the cell */
  6995.       temp_next->count = 1;                                 /* set count = 1 */
  6996.       temp_next->sel = sel;                           /* record the selector */
  6997.       temp_next->last_name_rec = temp_current;   /* back link to   last cell */
  6998.       temp_next->next_name_rec = NULL;                  /* next link is null */
  6999.       temp_current->next_name_rec = temp_next;      /* next link to new cell */
  7000.     }
  7001.  
  7002.       /* bubble cell up the list until above all cells with lower count */
  7003.  
  7004.  while ((temp_current->last_name_rec != NULL) 
  7005.         && (temp_current->count > temp_current->last_name_rec->count))
  7006.   {
  7007.     strcpy (temp_rec.name, temp_current->name);
  7008.     temp_rec.count = temp_current->count;
  7009.     strcpy (temp_current->name, temp_current->last_name_rec->name);
  7010.     temp_current->count = temp_current->last_name_rec->count;
  7011.     strcpy (temp_current->last_name_rec->name, temp_rec.name);
  7012.     temp_current->last_name_rec->count = temp_rec.count;
  7013.     temp_current = temp_current->last_name_rec;  
  7014.   }
  7015.  
  7016.   return name_list;                    /* return pointer to list as modified */
  7017. }    
  7018.  
  7019. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ tally_list_name ^^^^*/
  7020.  
  7021. #pragma subtitle("tally_list_year ()")
  7022. #pragma page()
  7023.  
  7024. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv tally_list_year vvvv*/
  7025.  
  7026. /*----------------------------------------------------------------------------+
  7027. |                                                                             |
  7028. | SYNOPSIS                                                                    |
  7029. | ~~~~~~~~                                                                    |
  7030. |   #include <os2.h>                                                          |
  7031. |   #include <stdio.h>                                                        |
  7032. |   #include <string.h>                                                       |
  7033. |   void tally_list_year (char *new_year, struct YEARRECORD far *year_list)   |
  7034. |                                                                             |
  7035. | FUNCTION                                                                    |
  7036. | ~~~~~~~~                                                                    |
  7037. |   Creates a year list if not previously created.  Compares new_year to      |
  7038. |   each cell in the list until a year match is found or the end of the       |
  7039. |   list is reached.  If a match is found, the count is incremented.  If      |
  7040. |   no match is found, a new cell is added with the new year.  The cell       |
  7041. |   for the new year is bubbled up the list to maintain frequency order.      |
  7042. |                                                                             |
  7043. | RETURNS                                                                     |
  7044. | ~~~~~~~                                                                     |
  7045. |   Pointer to head of doubly-linked year list.                               |
  7046. |                                                                             |
  7047. |                                                                             |
  7048. | NOTES                                                                       |
  7049. | ~~~~~                                                                       |
  7050. |   Uses MSC extensions and may not be portable.                              |
  7051. |                                                                             |
  7052. |                                                                             |
  7053. +----------------------------------------------------------------------------*/
  7054.  
  7055. struct YEARRECORD far *tally_list_year (new_year, year_list)
  7056.   char *new_year;                                      /*pointer to new year */
  7057.   struct YEARRECORD far *year_list;          /* pointer to head of year list */
  7058.   
  7059.  
  7060. {
  7061.   USHORT                 cbString;                      /* string byte count */
  7062.   char                  *char_buff;                         /* string buffer */
  7063.   HVIO                   hvio = 0;                           /* video handle */
  7064.   static int             out_of_memory = FALSE;        /* out of memory flag */    
  7065.   SEL                    sel;                       /* memory block selector */
  7066.   struct YEARRECORD far *temp_current;         /* ptr to current year record */
  7067.   struct YEARRECORD far *temp_next;               /* ptr to next year record */
  7068.   struct YEARRECORD      temp_rec;                  /* temporary year record */
  7069.   
  7070.   if (new_year[0] == '\0')                     /* if no new year, do nothing */
  7071.     return year_list;                               /* return list unchanged */
  7072.  
  7073.          /* if no list, establish one */
  7074.  
  7075.   if (year_list == NULL)                  /* if no pointer allocated to list */
  7076.     {
  7077.       out_of_memory = DosAllocSeg ((sizeof (struct YEARRECORD)), &sel, 0);
  7078.       if (out_of_memory)       /* allocate memory and test for out of memory */
  7079.         return year_list;                     /* return if allocation failed */
  7080.       year_list = MAKEP (sel, 0);        /* make a pointer from the selector */
  7081.       strcpy (year_list->year, new_year);  /* copy the year to the list head */
  7082.       year_list->count = 1;                               /* set counter = 1 */
  7083.       year_list->sel = sel;                           /* record the selector */
  7084.       year_list->last_year_rec = NULL;              /* set back link to null */
  7085.       year_list->next_year_rec = NULL;           /* set forward link to null */
  7086.       return year_list;                                /* return the pointer */
  7087.     }
  7088.   
  7089.          /* move down the list until year match found or end of list */
  7090.  
  7091.   temp_current = year_list;                   /* set current to head of list */
  7092.   while ((temp_current->next_year_rec != NULL)    /* while not end of list - */
  7093.      && (strcmp (temp_current->year, new_year)))       /* and no year match - */
  7094.     {
  7095.     temp_current = temp_current->next_year_rec;     /* move down to next link */
  7096.     }
  7097.  
  7098.          /* if match found, increment count */
  7099.          /* if no match, then add new cell to end of list */
  7100.  
  7101.   if ((strcmp (temp_current->year, new_year)) == 0)       /* if year match - */
  7102.     temp_current->count = temp_current->count + 1;        /* increment count */
  7103.   else                                                        /* otherwise - */
  7104.     if (! (out_of_memory))                           /* if not out of memory */
  7105.     {
  7106.       out_of_memory = DosAllocSeg ((sizeof (struct YEARRECORD)), &sel, 0);
  7107.       if (out_of_memory)          /* allocate memory for new cell and test - */
  7108.       {
  7109.         char_buff = (char *) calloc (1, 0x100);
  7110.         sprintf (char_buff, "All available memory in use.");
  7111.         cbString = (USHORT)strlen(char_buff);
  7112.         VioWrtCharStr (char_buff,cbString,20,5,hvio);
  7113.         free (char_buff);
  7114.         return year_list;    /* return unchanged if memory allocation failed */
  7115.       }
  7116.       temp_next = MAKEP (sel, 0);        /* make a pointer from the selector */
  7117.       strcpy (temp_next->year, new_year); /* copy the new year into the cell */
  7118.       temp_next->count = 1;                                 /* set count = 1 */
  7119.       temp_next->sel = sel;                           /* record the selector */
  7120.       temp_next->last_year_rec = temp_current;     /* back link to last cell */
  7121.       temp_next->next_year_rec = NULL;                  /* next link is null */
  7122.       temp_current->next_year_rec = temp_next;      /* next link to new cell */
  7123.     }
  7124.  
  7125.          /* bubble cell up the list until above all cells with lower counts */
  7126.  
  7127.   while ((temp_current->last_year_rec != NULL) 
  7128.         && (temp_current->count > temp_current->last_year_rec->count))
  7129.   {
  7130.     strcpy (temp_rec.year, temp_current->year);
  7131.     temp_rec.count = temp_current->count;
  7132.     strcpy (temp_current->year, temp_current->last_year_rec->year);
  7133.     temp_current->count = temp_current->last_year_rec->count;
  7134.     strcpy (temp_current->last_year_rec->year, temp_rec.year);
  7135.     temp_current->last_year_rec->count = temp_rec.count;
  7136.     temp_current = temp_current->last_year_rec;  
  7137.   }
  7138.  
  7139.   return year_list;                    /* return pointer to list as modified */
  7140. }
  7141.  
  7142. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ tally_list_year ^^^^*/
  7143.  
  7144.  
  7145. #pragma subtitle("tally_sort()")
  7146. #pragma page()
  7147.  
  7148. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv tally_sort vvvv*/
  7149.  
  7150. /*----------------------------------------------------------------------------+
  7151. |                                                                             |
  7152. | SYNOPSIS                                                                    |
  7153. | ~~~~~~~~                                                                    |
  7154. |   include <stdio.h>                                                         |
  7155. |   void tally_sort (int sort_number, char sort_codes[], sort_counts[])       |
  7156. |                                                                             |
  7157. | FUNCTION                                                                    |
  7158. | ~~~~~~~~                                                                    |
  7159. |   Performs a bubble sort on a two arrays, sort_number elements long,        |
  7160. |   of corresponding pairs of character codes and frequency counts, so        |
  7161. |   that they are ordered highest to lowest according to frequency.           |
  7162. |                                                                             |
  7163. | RETURNS                                                                     |
  7164. | ~~~~~~~                                                                     |
  7165. |                                                                             |
  7166. |   Nothing.                                                                  |
  7167. |                                                                             |
  7168. |                                                                             |
  7169. | NOTES                                                                       |
  7170. | ~~~~~                                                                       |
  7171. |                                                                             |
  7172. |   Uses ANSI standard functions only; should be portable.                    |
  7173. |                                                                             |
  7174. |                                                                             |
  7175. |                                                                             |
  7176. |                                                                             |
  7177. +----------------------------------------------------------------------------*/
  7178.  
  7179. void tally_sort (sort_number, sort_codes, sort_counts)
  7180.  
  7181.   int               sort_number;             /* number of pairs to be sorted */
  7182.   char              sort_codes[];                /* array of character codes */
  7183.   int               sort_counts[];      /* array of integer frequency counts */
  7184.   
  7185. {
  7186.   int               i, j;                           /* array index variables */
  7187.   char              temp_code;           /* temporary character value holder */
  7188.   int               temp_count;            /* temporary integer value holder */
  7189.  
  7190.    
  7191.  
  7192.             /* bubble sort */
  7193.             /* (in repeated passes, adjacent elements out of sequence /*
  7194.             /* are swapped) */
  7195.  
  7196.   for (i = 0; i <= (sort_number - 2); i++)
  7197.     for (j = (sort_number - 1); j >= (i + 1); j--)
  7198.     {
  7199.       if (sort_counts[j] > sort_counts [j - 1])
  7200.       {
  7201.         temp_count = sort_counts [j];
  7202.         temp_code = sort_codes [j];
  7203.         sort_counts [j] = sort_counts [ j - 1];
  7204.         sort_codes [j] = sort_codes [j - 1];
  7205.         sort_counts [j - 1] = temp_count;
  7206.         sort_codes [j - 1] = temp_code;
  7207.       }
  7208.     }
  7209. }   
  7210.   
  7211.   
  7212.  
  7213. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ tally_sort ^^^^*/
  7214.  
  7215. #pragma subtitle("trans_comp()")
  7216. #pragma page()
  7217.  
  7218. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv trans_comp vvvv*/
  7219.  
  7220. /*----------------------------------------------------------------------------+
  7221. |                                                                             |
  7222. | SYNOPSIS                                                                    |
  7223. | ~~~~~~~~                                                                    |
  7224. |   #include <stdio.h>                                                        |
  7225. |   #include <string.h>                                                       |
  7226. |   #include <videocat.h>                                                     |
  7227. |   int trans_comp (struct MOVIETRANS *trans1, *trans2)                       |
  7228. |                                                                             |
  7229. | FUNCTION                                                                    |
  7230. | ~~~~~~~~                                                                    |
  7231. |  Compares the transactions pointed to by trans1 and trans2.  Initial        |
  7232. |  comparison is according to the result of comparing the moviedata record    |
  7233. |  portion of each transaction.  If the moviedata records are equal,          |
  7234. |  further comparison is by transaction code, to assure that deletes          |
  7235. |  precede adds for change transactions which delete an old record and        |
  7236. |  may add a new one with the same title and year but other data changed.     |
  7237. |                                                                             |
  7238. | RETURNS                                                                     |
  7239. | ~~~~~~~                                                                     |
  7240. |   less than zero if trans1 is less than trans2                              |
  7241. |   zero if trans1 is equal to trans2                                         |
  7242. |   greater than zero if trans1 is greater than trans2                        |
  7243. |                                                                             |
  7244. | NOTES                                                                       |
  7245. | ~~~~~                                                                       |
  7246. |   Comparison is used for sorting records in alphabetical sequence by        |
  7247. |   title.  Because of "remakes" two movies are allowed to have the same      |
  7248. |   title and they will be sequenced according to year of production.         |
  7249. |   When both title and year are the same, it is assumed that the records     |
  7250. |   both identify the same movie.  If transaction  codes are different,       |
  7251. |   the transactions may represent a change (delete old, add new)             |
  7252. +----------------------------------------------------------------------------*/
  7253.  
  7254. int trans_comp (trans1, trans2)
  7255.  
  7256. struct MOVIETRANS *trans1, *trans2;            /* pointers to 2 transactions */
  7257.  
  7258. {
  7259.   int               comp_result;                     /* result of comparison */
  7260.   extern int        rec_comp();                   /* func compares 2 records */
  7261.   
  7262.   if ((comp_result = rec_comp (&trans1->moviedata, &trans2->moviedata)) == 0)
  7263.   {
  7264.     if ((trans1->transaction == 'D') && (trans2->transaction == 'A'))
  7265.       comp_result = -1;
  7266.     if ((trans1->transaction == 'A') && (trans2->transaction == 'D'))
  7267.       comp_result = 1;
  7268.     if ((trans1->transaction == 'E') && (trans2->transaction != 'E'))
  7269.       comp_result = 1;
  7270.     if ((trans1->transaction != 'E') && (trans2->transaction == 'E'))
  7271.       comp_result = -1;
  7272.     if ((trans1->transaction != '\0') && (trans2->transaction == '\0'))
  7273.       comp_result = 1;
  7274.     if ((trans1->transaction == '\0') && (trans2->transaction != '\0'))
  7275.       comp_result = -1;
  7276.   }
  7277.   
  7278.   return (comp_result);
  7279. }
  7280. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trans_comp ^^^^^*/
  7281.  
  7282.  
  7283. #pragma subtitle("tree_display()")
  7284. #pragma page()
  7285.  
  7286. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv tree_display vvvv*/
  7287. /*----------------------------------------------------------------------------+
  7288. |                                                                             |
  7289. | SYNOPSIS                                                                    |
  7290. | ~~~~~~~~                                                                    |
  7291. |   #include <stdio.h>                                                        |
  7292. |   int tree_display (struct MOVIETRANS *tree_ptr, int count)                 |
  7293. |                                                                             |
  7294. | FUNCTION                                                                    |
  7295. | ~~~~~~~~                                                                    |
  7296. |   Displays transactions in a binary tree structure pointed to by            |
  7297. |   *tree_ptr, where count is the number of transactions already displayed    |
  7298. |   on the screen; pauses for user after 3 transactions have been displayed   |
  7299. |   and waits for signal from user before displaying more transactons.        |
  7300. | RETURNS                                                                     |
  7301. | ~~~~~~~                                                                     |
  7302. |   Number of transactions displayed on the screen after execution.           |
  7303. |                                                                             |
  7304. |                                                                             |
  7305. |                                                                             |
  7306. | NOTES                                                                       |
  7307. | ~~~~~                                                                       |
  7308. |   Calls other functions which use MSC extensions and may not be portable.   |
  7309. |   Calls itself recursively until the tree is completely traversed,          |
  7310. |   passing the number of transactions currently displayed to each recursive  |
  7311. |   invocation.                                                               |
  7312. |                                                                             |
  7313. |                                                                             |
  7314. +----------------------------------------------------------------------------*/
  7315.  
  7316. int tree_display (tree_ptr, count)          /*  display transactions in tree */
  7317.  
  7318.   struct MOVIETRANS        *tree_ptr;               /* ptr to tree structure */
  7319.   int                       count;             /* number displayed on screen */
  7320. {
  7321.   extern void               clear_screen();          /* func to clear screen */
  7322.   extern void               display();      /* func to display a transaction */
  7323.   extern char               pause();                 /* func pauses for user */
  7324.   
  7325.   if (tree_ptr != NULL)      /* if tree pointer is not null pointer, display */
  7326.   {                         /*  left subtree first, and get number displayed */
  7327.     count = tree_display (tree_ptr->ltransnode, count);
  7328.     {
  7329.       if (count == 0)         /* if no transactions already displayed, clear */
  7330.         clear_screen (YELLOW, BLACK);       /* screen and set display colors */
  7331.       display ((count * 6),tree_ptr);      /* display record at current node */
  7332.       if (++count >= 3)                       /* if 3 transactions displayed */
  7333.       {
  7334.         VioSetCurPos (23,0,0);
  7335.         pause();                                        /*    pause for user */
  7336.         count = 0;                                 /*    reset count to zero */
  7337.       }
  7338.     }
  7339.     count = tree_display (tree_ptr->rtransnode, count); /* right subtree next*/
  7340.   }
  7341.   return count;                         /* return number currently displayed */
  7342. }
  7343.  
  7344. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ tree_display ^^^^*/
  7345.  
  7346. #pragma subtitle("tree_insert()")
  7347. #pragma page()
  7348.  
  7349. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv tree_insert vvvv*/
  7350. /*----------------------------------------------------------------------------+
  7351. |                                                                             |
  7352. | SYNOPSIS                                                                    |
  7353. | ~~~~~~~~                                                                    |
  7354. |   #include <memory.h>                                                       |
  7355. |   struct MOVIETRANS *tree_insert (struct MOVIETRANS *tree_root, new_trans)  |
  7356. |                                                                             |
  7357. | FUNCTION                                                                    |
  7358. | ~~~~~~~~                                                                    |
  7359. |   Inserts a transaction pointed to by new_trans into a binary tree          |
  7360. |   pointed to by tree_root.                                                  |
  7361. |                                                                             |
  7362. |                                                                             |
  7363. | RETURNS                                                                     |
  7364. | ~~~~~~~                                                                     |
  7365. |   Pointer to the root of the binary tree structure.                         |
  7366. |                                                                             |
  7367. |                                                                             |
  7368. |                                                                             |
  7369. | NOTES                                                                       |
  7370. | ~~~~~                                                                       |
  7371. |   Memcpy() is declared in memory.h.  MOVIETRANS is a structure defined      |
  7372. |   in videocat.c.                                                            |
  7373. |                                                                             |
  7374. |                                                                             |
  7375. |                                                                             |
  7376. |                                                                             |
  7377. +----------------------------------------------------------------------------*/
  7378.  
  7379. struct MOVIETRANS *tree_insert (tree_root, new_trans)/* insert trans in tree */
  7380.  
  7381.   struct MOVIETRANS    *tree_root;               /* root of a tree structure */
  7382.   struct MOVIETRANS    *new_trans;                   /* ptr to a transaction */
  7383.  
  7384. {
  7385.   int                   cond;                   /* comparison condition code */
  7386.   static int            out_of_memory = FALSE;         /* out of memory flag */
  7387.   SEL                   sel;                        /* memory block selector */
  7388.   extern int            trans_comp();        /* func to compare transactions */
  7389.   
  7390.   if (tree_root == NULL)                     /* if tree root is null pointer */
  7391.     {
  7392.       out_of_memory = DosAllocSeg ((sizeof (struct MOVIETRANS)), &sel,0);
  7393.  
  7394.       tree_root = (struct MOVIETRANS *)calloc(1, sizeof(struct MOVIETRANS));
  7395.       if (out_of_memory)
  7396.       {
  7397.         printf ("Out of memory \n");
  7398.         return tree_root;
  7399.       }
  7400.       memcpy ((char *)tree_root, (char *)new_trans,
  7401.               sizeof(struct MOVIETRANS));                      /* copy trans */
  7402.       tree_root->sel = sel;
  7403.       tree_root->ltransnode = tree_root->rtransnode = NULL;  /* nodes = Null */
  7404.     }
  7405.   else if ((cond = trans_comp (new_trans, tree_root)) == 0) /* if new = root */
  7406.     {
  7407.       memcpy ((char *)&tree_root->moviedata, (char *)&new_trans->moviedata,
  7408.         sizeof(struct MOVIERECORD));  /* copy new data record */
  7409.     }
  7410.   else if (cond < 0)        /* if new less than root insert new at left node */
  7411.     tree_root->ltransnode = tree_insert (tree_root->ltransnode, new_trans);
  7412.   else if (cond > 0)    /* if new greater than root insert new at right node */
  7413.     tree_root->rtransnode = tree_insert (tree_root->rtransnode, new_trans);
  7414.   return (tree_root);                              /* return pointer to root */
  7415. }
  7416.  
  7417. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ tree_insert ^^^^*/
  7418.  
  7419. #pragma subtitle("trim()")
  7420. #pragma page()
  7421.  
  7422. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv trim vvvv*/
  7423. /*----------------------------------------------------------------------------+
  7424. |                                                                             |
  7425. | SYNOPSIS                                                                    |
  7426. | ~~~~~~~~                                                                    |
  7427. |   #include <stdio.h>                                                        |
  7428. |   #include <string.h>                                                       |
  7429. |   #include <ctype.h>                                                        |
  7430. |   void trim (char *string_ptr)                                              |
  7431. |                                                                             |
  7432. | FUNCTION                                                                    |
  7433. | ~~~~~~~~                                                                    |
  7434. |   Trims leading and trailing whitespace charactrs from a string.            |
  7435. |                                                                             |
  7436. | RETURNS                                                                     |
  7437. | ~~~~~~~                                                                     |
  7438. |   Nothing.                                                                  |
  7439. |                                                                             |
  7440. |                                                                             |
  7441. |                                                                             |
  7442. | NOTES                                                                       |
  7443. | ~~~~~                                                                       |
  7444. |   Used to edit console input to delete any leading or trailing              |
  7445. |   spaces.                                                                   |
  7446. |                                                                             |
  7447. |                                                                             |
  7448. +----------------------------------------------------------------------------*/
  7449.  
  7450. void trim (string_ptr)           /* func trims leading & trailing whitespace */
  7451.  
  7452. char *string_ptr;                                       /* pointer to string */
  7453.  
  7454. {
  7455.   int           count;                                            /* counter */
  7456.   int           last_char;              /* index of last character in string */
  7457.  
  7458.             /* delete leading white space */
  7459.  
  7460.   while (isspace (string_ptr [0]))           /* while 1st char is whitespace */
  7461.                                          /*  move rest of string back 1 byte */
  7462.     for (count = 0; count <= strlen (string_ptr); count++)
  7463.       string_ptr [count] = string_ptr [count + 1];
  7464.  
  7465.             /* delete trailing white space */
  7466.  
  7467.   last_char = strlen (string_ptr) - 1;             /* get index of last char */
  7468.   while (isspace (string_ptr [last_char]))  /* while last char is whitespace */
  7469.     {
  7470.     string_ptr [last_char] = '\0';             /*   change last char to null */
  7471.     last_char = strlen (string_ptr) - 1;     /*   get index of new last char */
  7472.     }
  7473. }
  7474.  
  7475. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trim ^^^^*/
  7476.  
  7477.  
  7478. #pragma subtitle("update()")
  7479. #pragma page()
  7480.  
  7481. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv update vvvv*/
  7482.  
  7483. /*----------------------------------------------------------------------------+
  7484. |                                                                             |
  7485. | SYNOPSIS                                                                    |
  7486. | ~~~~~~~~                                                                    |
  7487. |   #include <stdio.h>                                                        |
  7488. |   struct MOVIETRANS *update (struct MOVIETRANS *root, char *base_file_id,   |
  7489. |                         char *work_file_id, struct MOVIETRANS *trans_buff)  |
  7490. | FUNCTION                                                                    |
  7491. | ~~~~~~~~                                                                    |
  7492. |   Processes transactions contained in a binary tree pointe to by root       |
  7493. |   against records contained in the file whose name is pointed to by         |
  7494. |   base_file_id, writing to a work file whose name is pointed to by          |
  7495. |   work_file_id, and using the buffer trans_buff for processing.             |
  7496. | RETURNS                                                                     |
  7497. | ~~~~~~~                                                                     |
  7498. |   The pointer to the transaction tree, which is null after a successful     |
  7499. |   update.                                                                   |
  7500. |                                                                             |
  7501. |                                                                             |
  7502. | NOTES                                                                       |
  7503. | ~~~~~                                                                       |
  7504. |                                                                             |
  7505. |                                                                             |
  7506. |                                                                             |
  7507. |                                                                             |
  7508. |                                                                             |
  7509. |                                                                             |
  7510. +----------------------------------------------------------------------------*/
  7511.  
  7512. struct MOVIETRANS *update (root, base_file_id, work_file_id, trans_buff)
  7513.  
  7514.   struct MOVIETRANS    *root;              /* pointer to root of binary tree */
  7515.   char                 *base_file_id;        /* pointer to name of base file */
  7516.   char                 *work_file_id;        /* pointer to name of work file */
  7517.   struct MOVIETRANS    *trans_buff;         /* pointer to transaction buffer */
  7518.   
  7519. {
  7520.  
  7521.   FILE                 *basef_ptr;                       /* base file stream */
  7522.   char                 *buf1;                             /* file i/o buffer */
  7523.   char                 *buf2;                             /* file i/o buffer */
  7524.   USHORT                cbString;                       /* string byte count */
  7525.   char                 *char_buff;                          /* string buffer */
  7526.   extern void           clear_screen();  /* func clears screen & sets colors */
  7527.   int                   count;              /* counter for records processed */
  7528.   extern void           cur_size();
  7529.   struct MOVIERECORD   *current_rec_buf;             /* holds current record */
  7530.   extern void           editRdata();
  7531.   HVIO                  hvio = 0;                            /* video handle */
  7532.   extern int            has_color();         /* funct tests if color display */
  7533.   extern int            in_order();   /* func processes transactions in tree */
  7534.   struct MOVIERECORD   *last_rec_buf;              /* holds last record read */
  7535.   extern char           pause();                      /* func waits for user */
  7536.   FILE                 *workf_ptr;                       /* work file stream */
  7537.  
  7538.           /* set up screen and open files */
  7539.  
  7540.   char_buff = (char *) calloc (1, 0x100);
  7541.   cur_size (CURSOFF);                        /* call func to turn off cursor */
  7542.   clear_screen (YELLOW, BLACK);         /* clear screen & set display colors */
  7543.   sprintf (char_buff, "UPDATING - READING OLD BASE FILE ...");/* advise user */
  7544.   cbString = (USHORT)strlen(char_buff);
  7545.   VioWrtCharStr (char_buff, cbString, 11, 11, hvio);
  7546.   VioSetCurPos (23,0,hvio);
  7547.   trans_buff = (struct MOVIETRANS *)memset                   /* clear buffer */
  7548.      ((char *)trans_buff, '\0', sizeof(struct MOVIETRANS));
  7549.   buf1 = calloc (1, BIGBUFF);               /* allocate memory to i/o buffer */
  7550.   buf2 = calloc (1, BIGBUFF);               /* allocate memory to i/o buffer */
  7551.   current_rec_buf = calloc (1, sizeof (struct MOVIERECORD));
  7552.   last_rec_buf = calloc (1, sizeof (struct MOVIERECORD));
  7553.  
  7554.   workf_ptr = fopen (work_file_id, "wb");                  /* open work file */
  7555.   setvbuf (workf_ptr, buf1, _IOFBF, BIGBUFF); /* use big buffer for file i/o */
  7556.   if (workf_ptr == NULL)                /* if file not successfully opened - */
  7557.   {
  7558.     printf ("\n Error in opening work file.\n");              /* - warn user */
  7559.     pause();                                              /* - wait for user */
  7560.     fcloseall();                                        /* - close all files */
  7561.     if (has_color())               /* restore cursor appropriate for display */
  7562.       cur_size (CGACURSNORM);
  7563.     else
  7564.       cur_size (MONOCURSNORM);
  7565.     free (char_buff);
  7566.     return root;                                 /* return pointer unchanged */
  7567.   }
  7568.   basef_ptr = fopen (base_file_id, "rb");                  /* open base file */
  7569.   setvbuf (basef_ptr, buf2, _IOFBF, BIGBUFF); /* use big buffer for file i/o */
  7570.   if (basef_ptr == NULL)                /* if file not successfully opened - */
  7571.   {
  7572.     printf ("\n Error in opening base file.\n");              /* - warn user */
  7573.     pause();                                              /* - wait for user */
  7574.     fcloseall();                                        /* - close all files */
  7575.     if (has_color())               /* restore cursor appropriate for display */
  7576.       cur_size (CGACURSNORM);
  7577.     else
  7578.       cur_size (MONOCURSNORM);
  7579.     free (char_buff);
  7580.     return root;                               /* - return pointer unchanged */
  7581.   }
  7582.  
  7583.              /* process update  from base file and transactions */
  7584.              /*  to work file */
  7585.              
  7586.   count = 1;                                      /* initialize counter at 1 */
  7587.   count = (in_order (workf_ptr, basef_ptr, root, trans_buff, count));
  7588.   if (count != 0)
  7589.   {               /* if transactions in binary tree successfully processed - */
  7590.     root = NULL;                 /* if successful, all nodes have been freed */
  7591.     while (!(feof (basef_ptr)))            /* - while not end of base file - */
  7592.     {
  7593.       if ((trans_buff->transaction == '\0')          /* -- if buffer empty - */
  7594.         && ((fread ((char *)&trans_buff->moviedata, sizeof(struct MOVIERECORD),
  7595.         1, basef_ptr)) != 1))                               /* read a record */
  7596.       {                                                   /* if read error - */
  7597.         if (feof(basef_ptr))                          /* - if EOF break loop */
  7598.         {
  7599.           trans_buff->transaction = 'E';
  7600.           break;                        /*   and continue (normal condition) */
  7601.         }
  7602.         else 
  7603.         {                                         /* - if other read error - */
  7604.           printf ("\nError in reading base file.\n");           /* warn user */
  7605.           pause();                                          /* wait for user */
  7606.           fcloseall();
  7607.           if (has_color())         /* restore cursor appropriate for display */
  7608.             cur_size (CGACURSNORM);
  7609.           else
  7610.             cur_size (MONOCURSNORM);
  7611.           free (char_buff);
  7612.           return root;              /* break off search (abnormal condition) */
  7613.         }
  7614.       }
  7615.       else
  7616.       {
  7617.         trans_buff->transaction = 'B';/* code buffer to indicate base record */
  7618.         sprintf (char_buff,"%4d ", count++); /*- display and increment count */
  7619.         cbString = (USHORT)strlen(char_buff);
  7620.         VioWrtCharStr(char_buff,cbString,11,50,hvio);
  7621.       }  
  7622.       if ((trans_buff->transaction == 'B') /* if buffer contains base record */
  7623.          && ((fwrite ((char *)&trans_buff->moviedata,
  7624.              sizeof(struct MOVIERECORD),
  7625.          1, workf_ptr)) != 1))          /* write the record to the work file */
  7626.       {                                                  /* if write error - */
  7627.         printf ("\nError in writing work file.\n");             /* warn user */
  7628.         pause();                                            /* wait for user */
  7629.         fcloseall();
  7630.         if (has_color())           /* restore cursor appropriate for display */
  7631.           cur_size (CGACURSNORM);
  7632.         else
  7633.           cur_size (MONOCURSNORM);
  7634.         free (char_buff);
  7635.         return root;               /* break off process (abnormal condition) */
  7636.       }
  7637.       else trans_buff->transaction = '\0';    /* otherwise code buffer empty */
  7638.     }
  7639.     fclose (workf_ptr);                                   /* close work file */
  7640.     fclose (basef_ptr);                                   /* close base file */
  7641.  
  7642.           /* transfer updated file from work file to base file */
  7643.           
  7644.     workf_ptr = fopen (work_file_id, "rb");       /* open work file for read */
  7645.     setvbuf (workf_ptr, buf1, _IOFBF, BIGBUFF);            /* use big buffer */
  7646.     if (workf_ptr == NULL)              /* if file not successfully opened - */
  7647.     {
  7648.       printf ("\n Error in opening work file.\n");            /* - warn user */
  7649.       pause();                                            /* - wait for user */
  7650.       fcloseall();                                        /* close all files */
  7651.       if (has_color())             /* restore cursor appropriate for display */
  7652.         cur_size (CGACURSNORM);
  7653.       else
  7654.         cur_size (MONOCURSNORM);
  7655.       free (char_buff);
  7656.       return root;              /* - return pointer to binary tree unchanged */
  7657.     }
  7658.     basef_ptr = fopen (base_file_id, "wb");      /* open base file for write */
  7659.     setvbuf (basef_ptr, buf2, _IOFBF, BIGBUFF);            /* use big buffer */
  7660.     if (basef_ptr == NULL)              /* if file not successfully opened - */
  7661.     {
  7662.       printf ("\n Error in opening base file.\n");            /* - warn user */
  7663.       pause();                                            /* - wait for user */
  7664.       fcloseall();                                      /* - close all files */
  7665.       if (has_color())             /* restore cursor appropriate for display */
  7666.         cur_size (CGACURSNORM);
  7667.       else
  7668.         cur_size (MONOCURSNORM);
  7669.       free (char_buff);
  7670.       return root;                                /* - return root unchanged */
  7671.     }
  7672.     count = 1;                             /* initialize record counter at 1 */
  7673.     current_rec_buf = (struct MOVIERECORD *)memset         /* clears buffers */
  7674.       ((char *)current_rec_buf, '\0', sizeof(struct MOVIERECORD));
  7675.     last_rec_buf = (struct MOVIERECORD *)memset            /* clears buffers */
  7676.       ((char *)last_rec_buf, '\0', sizeof(struct MOVIERECORD));
  7677.     sprintf (char_buff,"UPDATING - WRITING NEW BASE FILE ...");
  7678.     cbString = (USHORT)strlen(char_buff);
  7679.     VioWrtCharStr (char_buff,cbString,11,11,hvio);
  7680.     while (!(feof (workf_ptr)))           /* while not at end of work file - */
  7681.     {
  7682.       if ((fread ((char *)current_rec_buf, sizeof(struct MOVIERECORD),
  7683.          1, workf_ptr)) != 1)                               /* read a record */
  7684.       {                                                   /* if read error - */
  7685.         if (feof(workf_ptr))                          /* - if EOF break loop */
  7686.           break;                        /*   and continue (normal condition) */
  7687.         else 
  7688.         {                                         /* - if other read error - */
  7689.           printf ("\nError in reading work file.\n");           /* warn user */
  7690.           pause();                                          /* wait for user */
  7691.           fcloseall();                                    /* close all files */
  7692.           if (has_color())         /* restore cursor appropriate for display */
  7693.             cur_size (CGACURSNORM);
  7694.           else
  7695.             cur_size (MONOCURSNORM);
  7696.           free (char_buff);
  7697.           return root;                              /* return root unchanged */
  7698.         }
  7699.       }
  7700.            /*  correct for justification change from prior versions */
  7701.  
  7702.       editRdata (current_rec_buf->loc1, LOCLENGTH);
  7703.       editRdata (current_rec_buf->loc2, LOCLENGTH);
  7704.       editRdata (current_rec_buf->year, YEARLENGTH);
  7705.  
  7706.       if ((rec_comp (current_rec_buf, last_rec_buf)) > 0)   /* test sequence */
  7707.       {
  7708.         if ((fwrite ((char *)current_rec_buf, sizeof(struct MOVIERECORD),
  7709.            1, basef_ptr)) != 1)                 /* write record to base file */
  7710.         {                                                /* if write error - */
  7711.           printf ("\nError in writing base file.\n");           /* warn user */
  7712.           pause();                                          /* wait for user */
  7713.           fcloseall();                                    /* close all files */
  7714.           if (has_color())         /* restore cursor appropriate for display */
  7715.             cur_size (CGACURSNORM);
  7716.           else
  7717.             cur_size (MONOCURSNORM);
  7718.           free (char_buff);
  7719.           return root;                              /* return root unchanged */
  7720.         }
  7721.         else  /* if record successfully transferred from work to base file - */
  7722.         {
  7723.           sprintf (char_buff, "%4d ", count++);    /* - display record count */
  7724.           cbString = (USHORT)strlen(char_buff);
  7725.           VioWrtCharStr (char_buff,cbString,11,50,hvio);
  7726.           memmove ((char *)last_rec_buf, (char *)current_rec_buf,
  7727.                   sizeof(struct MOVIERECORD));
  7728.         }            
  7729.       }
  7730.       else
  7731.       {
  7732.         sprintf (char_buff, "Discarding record out of sequence: %s",
  7733.                             current_rec_buf->title);
  7734.         cbString = (USHORT)strlen(char_buff);
  7735.         VioWrtCharStr (char_buff, cbString, 20,11,hvio);
  7736.       }
  7737.     }    
  7738.     fclose (workf_ptr);                                   /* close work file */
  7739.     fclose (basef_ptr);                                   /* close base file */
  7740.     free (current_rec_buf);
  7741.     free (last_rec_buf);
  7742.     free (buf1);                 /* free memory allocated to file i/o buffer */
  7743.     free (buf2);                 /* free memory allocated to file i/o buffer */
  7744.   }
  7745.  
  7746.   if (has_color())                 /* restore cursor appropriate for display */
  7747.     cur_size (CGACURSNORM);
  7748.   else
  7749.     cur_size (MONOCURSNORM);
  7750.   
  7751.   pause();
  7752.   free (char_buff);
  7753.   return root;                    /* return root (NULL if update successful) */
  7754. }
  7755.  
  7756. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ update ^^^^*/
  7757.  
  7758. #pragma subtitle("verify()")
  7759. #pragma page()
  7760.  
  7761. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv verify vvvv*/
  7762.  
  7763. /*----------------------------------------------------------------------------+
  7764. |                                                                             |
  7765. | SYNOPSIS                                                                    |
  7766. | ~~~~~~~~                                                                    |
  7767. |   #include <stdio.h>                                                        |
  7768. |   int verify()                                                              |
  7769. |                                                                             |
  7770. | FUNCTION                                                                    |
  7771. | ~~~~~~~~                                                                    |
  7772. |   Asks user to verify data just displayed and enter Y or N according        |
  7773. |   to whether or not it is correct.                                          |
  7774. |                                                                             |
  7775. |                                                                             |
  7776. | RETURNS                                                                     |
  7777. | ~~~~~~~                                                                     |
  7778. |   TRUE if first character of user's response is 'Y' or 'y'; otherwise       |
  7779. |   returns FALSE.                                                            |
  7780. |                                                                             |
  7781. |                                                                             |
  7782. | NOTES                                                                       |
  7783. | ~~~~~                                                                       |
  7784. |   TRUE and FALSE must be defined by macros in the calling program.          |
  7785. |                                                                             |
  7786. |                                                                             |
  7787. |                                                                             |
  7788. +----------------------------------------------------------------------------*/
  7789.  
  7790. int verify()                          /* func gets user verification of data */
  7791.  
  7792. {
  7793.  
  7794.   char                  response [INPUTLENGTH];         /* user input buffer */
  7795.   extern void           trim();        /* func trims lead & trail whitespace */
  7796.  
  7797.   printf (" Is this data correct? (Y/N) -> ");      /* prompt user to verify */
  7798.   gets (response);                                      /* get user response */
  7799.   trim (response);                                     /* trim user response */
  7800.   if ((response[0] == 'Y') || (response[0] == 'y'))   /* if 1st char of user */
  7801.     return TRUE;                                    /* is Y or y return TRUE */
  7802.   else                                             /* otherwise return FALSE */
  7803.     return FALSE;
  7804.  
  7805. }   
  7806.  
  7807. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ verify ^^^^*/
  7808.  
  7809. #pragma subtitle("welcome()")
  7810. #pragma page()
  7811.  
  7812. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv welcome vvvv*/
  7813. /*----------------------------------------------------------------------------+
  7814. |                                                                             |
  7815. | SYNOPSIS                                                                    |
  7816. | ~~~~~~~~                                                                    |
  7817. |   #include <stdio.h>                                                        |
  7818. |   void welcome ()                                                           |
  7819. |                                                                             |
  7820. | FUNCTION                                                                    |
  7821. | ~~~~~~~~                                                                    |
  7822. |   Clears screen, opens window, draws box, and displays main menu.           |
  7823. |                                                                             |
  7824. |                                                                             |
  7825. |                                                                             |
  7826. | RETURNS                                                                     |
  7827. | ~~~~~~~                                                                     |
  7828. |   Nothing.                                                                  |
  7829. |                                                                             |
  7830. |                                                                             |
  7831. |                                                                             |
  7832. | NOTES                                                                       |
  7833. | ~~~~~                                                                       |
  7834. |                                                                             |
  7835. |                                                                             |
  7836. |                                                                             |
  7837. |                                                                             |
  7838. |                                                                             |
  7839. |                                                                             |
  7840. +----------------------------------------------------------------------------*/
  7841.  
  7842. void welcome()                                            /* welcome routine */
  7843.  
  7844. {
  7845.   USHORT            cbString;                           /* string byte count */
  7846.   char             *char_buff;                              /* string buffer */
  7847.   extern void       clear_screen();    /* func clears screen and sets colors */
  7848.   extern void       draw_box();                  /* func draws box on screen */
  7849.   HVIO              hvio = 0;                                /* video handle */
  7850.   extern char       pause();                   /* func pauses for user input */
  7851.   extern void       set_cursor();               /* func sets cursor position */
  7852.   extern void       window();         /* func opens window on screen display */
  7853.  
  7854.   char_buff = (char *) calloc (1, 0x100);
  7855.   clear_screen (LBLUE, BLACK);                  /* clear screen & set colors */
  7856.   window (10,70,3,18,RED,BLUE);                         /* open outer window */
  7857.   window (12,68,5,16,LWHITE,BLUE);                     /* open innner window */
  7858.   draw_box ('p',11,69,3,18);                           /* draw box in window */
  7859.  
  7860.   sprintf (char_buff, "V I D E O C A T");            /* display program name */
  7861.   cbString = (USHORT)strlen(char_buff);
  7862.   VioWrtCharStr(char_buff,cbString,7,32,hvio);
  7863.  
  7864.   sprintf (char_buff,"Video Cassette Catalog");
  7865.   cbString = (USHORT)strlen(char_buff);
  7866.   VioWrtCharStr(char_buff,cbString,9,29,hvio);
  7867.  
  7868.   sprintf (char_buff,"Version 6.0");               /* display version number */
  7869.   cbString = (USHORT)strlen(char_buff);
  7870.   VioWrtCharStr(char_buff,cbString,11,33,hvio);
  7871.  
  7872.   set_cursor (16,14,0);                                   /* position cursor */
  7873.   sprintf (char_buff,"(C)opyright 1986, 1987, 1988           W.A. Jackson");     /* (C) */
  7874.   cbString = (USHORT)strlen(char_buff);
  7875.   VioWrtCharStr(char_buff,cbString,16,14,hvio);
  7876.  
  7877.   set_cursor (22, 10, 0);                                     /* move cursor */
  7878.   pause();                                                  /* wait for user */
  7879.   window (12,68,5,16,LWHITE,BLUE);                     /* clear inner window */
  7880.  
  7881.   sprintf (char_buff,"This program may be freely copied for personal use and");
  7882.   cbString = (USHORT)strlen(char_buff);
  7883.   VioWrtCharStr(char_buff,cbString,6,12,hvio);
  7884.  
  7885.   sprintf
  7886.      (char_buff,"transferred through public bulletin boards and shareware");
  7887.   cbString = (USHORT)strlen(char_buff);
  7888.   VioWrtCharStr(char_buff,cbString,7,12,hvio);
  7889.  
  7890.   sprintf (char_buff,"distributors making no more than a nominal charge for");
  7891.   cbString = (USHORT)strlen(char_buff);
  7892.   VioWrtCharStr(char_buff,cbString,8,12,hvio);
  7893.  
  7894.   sprintf (char_buff,"on-line time or diskette reproduction.  A voluntary ");
  7895.   cbString = (USHORT)strlen(char_buff);
  7896.   VioWrtCharStr(char_buff,cbString,9,12,hvio);
  7897.  
  7898.   sprintf (char_buff,"royalty payment to the author, in any amount you deem");
  7899.   cbString = (USHORT)strlen(char_buff);
  7900.   VioWrtCharStr(char_buff,cbString,10,12,hvio);
  7901.  
  7902.   sprintf
  7903.      (char_buff,"fair, will encourage further maintenance and enhancement.");
  7904.   cbString = (USHORT)strlen(char_buff);
  7905.   VioWrtCharStr(char_buff,cbString,11,12,hvio);
  7906.  
  7907.   sprintf (char_buff,"W. A. Jackson");
  7908.   cbString = (USHORT)strlen(char_buff);
  7909.   VioWrtCharStr(char_buff,cbString,13,30,hvio);
  7910.  
  7911.   sprintf (char_buff,"6529 Matilija Avenue");
  7912.   cbString = (USHORT)strlen(char_buff);
  7913.   VioWrtCharStr(char_buff,cbString,14,30,hvio);
  7914.  
  7915.   sprintf (char_buff,"Van Nuys, California 91401");
  7916.   cbString = (USHORT)strlen(char_buff);
  7917.   VioWrtCharStr(char_buff,cbString,15,30,hvio);
  7918.  
  7919.   free (char_buff);
  7920.   set_cursor (22, 10, 0);                                     /* move cursor */
  7921.   pause();                                                  /* wait for user */
  7922.  
  7923. }
  7924. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ welcome ^^^^*/
  7925.  
  7926. #pragma subtitle("whole_cat()")
  7927. #pragma page()
  7928.  
  7929. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv whole_cat vvvv*/
  7930. /*----------------------------------------------------------------------------+
  7931. |                                                                             |
  7932. | SYNOPSIS                                                                    |
  7933. | ~~~~~~~~                                                                    |
  7934. |   #include <stdio.h>                                                        |
  7935. |   #include <time.h>                                                         |
  7936. |   void whole_cat (char *base_file_id);                                      |
  7937. |                                                                             |
  7938. | FUNCTION                                                                    |
  7939. | ~~~~~~~~                                                                    |
  7940. |   Prints a complete catalog from the file identified by base_file_id.       |
  7941. |   Output is to printer or screen according to choice entered by user.       |
  7942. |                                                                             |
  7943. |                                                                             |
  7944. | RETURNS                                                                     |
  7945. | ~~~~~~~                                                                     |
  7946. |   Nothing.                                                                  |
  7947. |                                                                             |
  7948. |                                                                             |
  7949. |                                                                             |
  7950. | NOTES                                                                       |
  7951. | ~~~~~                                                                       |
  7952. |   Calls functions which use nonstandard extensions to ANSI C, so may        |
  7953. |   not be portable accross compilers and operating sytsems.                  |
  7954. |                                                                             |
  7955. |                                                                             |
  7956. |                                                                             |
  7957. |                                                                             |
  7958. +----------------------------------------------------------------------------*/
  7959.  
  7960. void whole_cat (base_file_id)
  7961.  
  7962.   char                  *base_file_id;    /* path and file name of base file */
  7963.  
  7964. {
  7965.  
  7966.   FILE                  *basef_pointer;      /* stream pointer for base file */
  7967.   struct MOVIERECORD    *base_record;          /* record read from base file */
  7968.   extern void            clear_screen();/* func clears screen and sets colors*/
  7969.   extern void            disp_rec();       /* func displays record on screen */
  7970.   char                   go_ahead = ' ';/* quit or go ahead signal from user */
  7971.   char                  *iobuf;                       /* buffer for file i/o */
  7972.   int                    out_count = 0;        /* counter for records output */
  7973.   char                   output_type = '\0';         /* code for output type */
  7974.   extern void            print_rec();       /* func prints record on printer */
  7975.   int   print_handle;                             /* file handle for printer */
  7976.   FILE *print_pointer;                                 /* stream for printer */
  7977.   extern char            outopt();           /* func gets user output choice */
  7978.   extern void            set_cursor();          /* func sets cursor position */
  7979.   long                   time_1;                   /* time marker in seconds */
  7980.   long                   time_2;                   /* time marker in seconds */
  7981.   extern void            window();                      /* func opens window */
  7982.  
  7983.                                               /* allocate memory for records */
  7984.   base_record = (struct MOVIERECORD *)calloc (1,sizeof (struct MOVIERECORD));
  7985.   iobuf = calloc (1, BIGBUFF);
  7986.   
  7987.   output_type = outopt();          /* call func to get output type from user */
  7988.  
  7989.   if (output_type == 'P')       /* if printed output, open stream to printer */
  7990.   {
  7991.     print_handle = open ("PRN", O_WRONLY);               /* open file handle */
  7992.     if (print_handle == -1)                           /* test for open error */
  7993.       perror ("open failed on PRN");
  7994.     print_pointer = fdopen (print_handle, "w");          /* associate stream */
  7995.     if (print_pointer == NULL)                             /* test for error */
  7996.     {
  7997.       perror ("fopen failed on print_handle");
  7998.       pause();                                              /* wait for user */
  7999.       return;                                       /* return to main module */
  8000.     }                         
  8001.  
  8002.   }  
  8003.             /* open base file and set up file i/o buffer */
  8004.  
  8005.   if ((basef_pointer = fopen (base_file_id, "rb")) == NULL) /* open base file*/
  8006.   {                                                     /* if unsuccessful - */
  8007.     printf ("\nUnable to open base file\n");                    /* warn user */
  8008.     pause();                                                /* wait for user */
  8009.     return;                                         /* return to main module */
  8010.   }
  8011.  
  8012.   setvbuf (basef_pointer, iobuf,_IOFBF, BIGBUFF); /* big buffer for file i/o */
  8013.   clear_screen (LWHITE,BLACK);
  8014.   window (0,79,0,0,LBLUE,BLACK);
  8015.   set_cursor (0,0,0);                             /* home cursor */
  8016.   if (output_type == 'P')
  8017.     printf ("Complete catalog being printed (printer must be ready)...");
  8018.   else
  8019.     printf ("Complete catalog being displayed on screen...");
  8020.   
  8021.   while ((!(feof (basef_pointer)))           /* loop while not end of file - */
  8022.          && (go_ahead != 'Q'))               /* and no quit signal from user */           
  8023.   {
  8024.     if ((fread ((char *)base_record, sizeof (struct MOVIERECORD),
  8025.          1, basef_pointer)) != 1)        /* read a record from the base file */
  8026.     {                                                     /* if read error - */
  8027.       if (!(feof(basef_pointer)))     /* - and not end of file (normal term) */
  8028.       {
  8029.          printf ("\nError in reading base file\n");             /* warn user */
  8030.          pause();                                           /* wait for user */
  8031.          fcloseall();                                     /* close all files */
  8032.          return;                                                    /* abort */
  8033.       }
  8034.       else break;               /* otherwise (normal) exit loop and continue */
  8035.     }
  8036.       set_cursor (23,0,0);
  8037.  
  8038.       switch (output_type)         /* select action according to output code */
  8039.       {
  8040.         case 'C' :                          /* for continuous screen display */
  8041.  
  8042.           disp_rec ((out_count * 5 + 2),base_record);  /* display the record */
  8043.           if (++out_count == 4)                            /* if screen full */
  8044.           {
  8045.             time(&time_1);                                /* set time marker */
  8046.             time_2 = time_1 + (long)2;
  8047.             while (time_1 <= time_2)                   /* allow time to read */
  8048.               time(&time_1);
  8049.             out_count = 0;                                    /* clear count */
  8050.           }          
  8051.           break;                                    /* exit switch selection */
  8052.  
  8053.         case 'S' :                              /* for paused screen display */
  8054.  
  8055.           if (out_count == 0)                      /* if clear screen needed */
  8056.           {
  8057.             clear_screen (LWHITE,BLACK);        /* clear screen & set colors */
  8058.             window (0,79,0,0,LBLUE,BLACK);
  8059.             set_cursor (23,0,0);                              /* home cursor */
  8060.             printf ("Complete catalog being displayed on screen...");
  8061.             set_cursor (23,0,0);                              /* home cursor */
  8062.           }
  8063.           disp_rec ((out_count * 5 + 2), base_record); /* display the record */
  8064.           if (++out_count == 4)                            /* if screen full */
  8065.           {
  8066.             go_ahead = qpause();                            /* wait for user */
  8067.             out_count = 0;                                    /* clear count */
  8068.           }
  8069.           break;                                    /* exit switch selection */
  8070.  
  8071.         case 'P' :                                     /* for printer output */
  8072.  
  8073.           if (out_count == 0)                          /* if new page needed */
  8074.             fprintf (print_pointer, "\r\f\n");                 /* page eject */
  8075.           print_rec (base_record, print_pointer);            /* print record */
  8076.           if (++out_count == 12)                             /* if page full */
  8077.             out_count = 0;                                    /* reset count */
  8078.           else                                                  /* otherwise */
  8079.             fprintf (print_pointer, "\n");                    /* skip a line */
  8080.           break;                                    /* exit switch selection */
  8081.  
  8082.       }
  8083.   }  
  8084.  
  8085.         /* shutdown after catalog completed */
  8086.  
  8087.   free ((char *)base_record);            /* free memory allocated to records */
  8088.   free (iobuf);
  8089.  
  8090.   if (fclose (basef_pointer) != NULL)              /* close base file stream */
  8091.     printf ("\nError in closing base file\n");
  8092.  
  8093.   if (output_type == 'P')                               /* if printer output */
  8094.   {
  8095.     fprintf (print_pointer, "\n\f");                      /* eject last page */
  8096.     if (fclose (print_pointer) == EOF)                       /* close stream */
  8097.        perror ("fclose failed on print_pointer");          /* test for error */
  8098.   }
  8099.  
  8100.   if ((output_type == 'S')||(output_type == 'C'));       /* if screen output */
  8101.   {
  8102.     set_cursor (23,0,0);
  8103.     pause();                                                /* wait for user */
  8104.   }
  8105. }
  8106.  
  8107.  
  8108.  
  8109. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ whole_cat ^^^^*/
  8110.  
  8111. #pragma subtitle("window()")
  8112. #pragma page()
  8113.  
  8114. /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv window vvvv*/
  8115.  
  8116. /*----------------------------------------------------------------------------+
  8117. |                                                                             |
  8118. | SYNOPSIS                                                                    |
  8119. | ~~~~~~~~                                                                    |
  8120. | #include <stdio.h>                                                          |
  8121. | #include <dos.h>                                                            |
  8122. | void window (int left_column, int right_columnun, int top_row,              |
  8123. |             int bottom_row, int foreground, int background)                 |
  8124. |                                                                             |
  8125. | FUNCTION                                                                    |
  8126. | ~~~~~~~~                                                                    |
  8127. |   Opens window bounded by lef_column, right_column, top_row, and            |
  8128. |   bottom row, with video attributes foreground color and background color.  |
  8129. |                                                                             |
  8130. | RETURNS                                                                     |
  8131. | ~~~~~~~                                                                     |
  8132. |   Nothing.                                                                  |
  8133. |                                                                             |
  8134. |                                                                             |
  8135. |                                                                             |
  8136. | NOTES                                                                       |
  8137. | ~~~~~                                                                       |
  8138. |   Uses VioScrollDn, an MSC extenstion which may not be portable accross     |
  8139. |   operating systems and compilers.                                          |
  8140. |                                                                             |
  8141. +----------------------------------------------------------------------------*/
  8142.  
  8143. void window (left_column, right_column, top_row, bottom_row,
  8144.               foreground, background)
  8145.  
  8146.   int           left_column;                       /* left boundry of window */
  8147.   int           right_column;                      /* right boundy of window */
  8148.   int           top_row;                            /* top boundry of window */
  8149.   int           bottom_row;                      /* bottom boundry of window */
  8150.   int           foreground;       /* color attribute of foreground in window */
  8151.   int           background;       /* color attribute of background in window */
  8152.  
  8153. {
  8154.  
  8155.   int           attribute;                          /* video color attribute */
  8156.   extern int    has_color();       /* func to check if color display present */
  8157.   USHORT        cbLines;
  8158.   BYTE          bCell[2];
  8159.   HVIO          hvio = 0;
  8160.   
  8161.             /* home cursor within window */
  8162.   
  8163.   VioSetCurPos (top_row, right_column, hvio);           
  8164.  
  8165.             /* set up color attribute byte for blank lines */
  8166.                 
  8167.   if (has_color())                             /* if color display present - */
  8168.     attribute = (0x10 * background) + foreground;  /* - construct attr. byte */
  8169.   else attribute = 0x7;                           /* else use mono attribute */
  8170.   bCell[0] = 0x20;
  8171.   bCell[1] = (BYTE)attribute;
  8172.   cbLines = bottom_row - top_row + 1;
  8173.   
  8174.             /* clear window and set colors */
  8175.   
  8176.   VioScrollDn (top_row, left_column, bottom_row, right_column,
  8177.                        cbLines, bCell, hvio);          
  8178.  
  8179. }
  8180.  
  8181. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ window ^^^^*/
  8182.  
  8183.              /*  Copyright 1986, 1987, 1988 W. A. Jackson */              
  8184. 
  8185.