/* * Copyright (c) 1994 - 1996 by * Digital Equipment Corporation, Maynard, MA * * This software is furnished under a license and may be used and copied * only in accordance with the terms of such license and with the * inclusion of the above copyright notice. This software or any other * copies thereof may not be provided or otherwise made available to any * other person. No title to and ownership of the software is hereby * transferred. * * The information in this software is subject to change without notice * and should not be construed as a commitment by Digital Equipment * Corporation. * * Digital(TM) assumes no responsibility for the use or reliability of its * software on equipment which is not supplied by Digital. * * Digital is a trademark of Digital Equipment Corporation. * *========== OpenVMS - Character-Cell and DECwindows Instructions ======== * * If your system manager copied the Mileage Reimbursement Demonstration * Application from the DECforms kit onto your system, you can run the * application by doing the following: * * To run the character-cell version: * * $ run forms$examples:forms$demo_mrf * * To run the DECwindows (Motif) version: * * $ set display/create/node=node-name * $ define forms$default_device decw$display * $ run forms$examples:forms$demo_mrf * * Any printing you do while running the Mileage Reimbursement Demonstration * Application will end up in your SYS$SCRATCH directory (usually your login * directory). * * The Mileage Reimbursement Demonstration Application in the C language * consists of three files: * * forms$demo_mrf_form.ifdl The IFDL source form * forms$demo_mrf_c.c The application itself * formsdef.h An include file with DECforms definitions * * The first two files are copied from the DECforms kit to the FORMS$EXAMPLES * directory and the last is put into SYS$LIBRARY. Putting the files in * FORMS$EXAMPLES is an installation option; talk to your system manager if * they aren't there. The FORMSDEF.H file is put into SYS$LIBRARY * unconditionally, so that you should be able to use it from all your C * programs using DECforms. * * To create a working version of the Mileage Reimbursement Application in * your own directory from these sources, follow these steps: * * 1. Set the default to your own directory: * * $ set default your-directory * * 2. Copy the source files to your own directory: * * $ copy forms$examples:forms$demo_mrf_form.ifdl, - * forms$demo_mrf_c.c [] * * 3. Translate the IFDL form file with the following command: * * $ forms translate forms$demo_mrf_form.ifdl * * This creates a binary form file named forms$demo_mrf_form.form. * * 4. Create the form object file with the following command: * * $ forms extract object /portable_api /form_load forms$demo_mrf_form.form * * This creates a forms object file named forms$demo_mrf_form.obj. * * 5. Compile the program with the following command: * * $ cc forms$demo_mrf_c * * This creates an object file named forms$demo_mrf_c.obj. * * 6. Create a file named mrf_opt.opt that contains the following line: * * SYS$LIBRARY:FORMS$PORTABLE_API.EXE/SHARE * * This file tells the linker to link in the shareable image that * contains the portable API entry points to the Form Manager. * * 7. Define the logical LNK$LIBRARY with the following command: * * $ define lnk$library sys$library:vaxcrtl * * This links in the C run-time library that defines the C forms calls. * * 8. Link the C program with the following command: * * $ link forms$demo_mrf_c, forms$demo_mrf_form, mrf_opt/opt * * 9. To prepare to run this application on character-cell devices, define * the logical FORMS$DEFAULT_DEVICE with the following command: * * $ define forms$default_device sys$input: * * 10. To prepare to run this application on DECwindows, define * the logical FORMS$DEFAULT_DEVICE with the following command: * * $ define forms$default_device decw$display: * * 11. To create a trace file that will describe each action taken * during the course of the application session, define the logical * FORMS$TRACE with the following command: * * $ define forms$trace t * * 12. To the application, enter the following command: * * $ run forms$demo_mrf_c * * If you turned on the trace file, running the application will * produce a log file named forms$demo_mrf_form.trace. * *======================================================================= */ #include #include #define EMPNAME 32 #define EMPBADGE 6 #define EMPCC 3 #define EMPADDRESS 120 #define EMPREASON 64 #define TRIPDATE 8 #define TRIPFROM 3 #define TRIPTO 3 #define TRIPRECORD 36 /* * Structure format declarations for records that will be sent to the form */ typedef struct { char employee_name[EMPNAME], badge_number[EMPBADGE], cost_center[EMPCC], address[EMPADDRESS], reason[EMPREASON]; } Hdr_Info_Record; typedef struct { char trip_date[TRIPDATE], trip_from[TRIPFROM], trip_to[TRIPTO]; unsigned long miles, amount, toll, subtotal; } Trip_Record; typedef struct { unsigned long total_miles, total_amount, total_tolls, form_total; } Totals_Record; /* * Static storage */ Hdr_Info_Record header_info_record; /* The header info record */ Trip_Record trips_record[TRIPRECORD]; /* Array of trip records */ Totals_Record totals_record; /* totals for all trips */ /* * Create instances from datatypes in forms_def header file */ Forms_Session_Id session_id; Forms_Form_Object MRF_FORM; /* linked form name */ Forms_Status status; Forms_Record_Data header_info_record_descr; /* record */ Forms_Record_Data trips_record_descr; /* record */ Forms_Record_Data totals_record_descr; /* record */ Forms_Request_Options request_options[2]; /* form object for linked form*/ Forms_Session_Id print_session; /* session for creating print form */ /* * Routine: main * * Functional Description: * * Enables the form session and performs the receive requests necessary to * obtain the employee and the trips data. Note that although these * operations are performed in two separate requests for simplicity, a * single request receiving both records would be more efficient and is * suitable for this situation since the application performs no operations * between the separate requests. */ int main (void) { /* * Set up the request options for linking the form object file and * enable the form. */ request_options[0].option = forms_c_opt_form; request_options[0].form.object = MRF_FORM; request_options[1].option = forms_c_opt_end; status = forms_enable (session_id, /* session id returned */ NULL, /* current device */ NULL, /* name of form file */ "MRF_FORM", /* name of the form */ request_options); /* request options */ /* * Obtain the employee header information -- structure must contain the length * and address of the record being received from DECforms. */ header_info_record_descr.data_record = &header_info_record; header_info_record_descr.data_length = sizeof(header_info_record); header_info_record_descr.shadow_record = NULL; header_info_record_descr.shadow_length = 0; status = forms_receive (session_id, /* session id */ "header_info_record", /* form record in IFDL */ &header_info_record_descr, /* record in program */ NULL); /* no request options */ /* * Obtain the information on all the trips made. */ trips_record_descr.data_record = &trips_record; trips_record_descr.data_length = sizeof(trips_record); trips_record_descr.shadow_record = NULL; trips_record_descr.shadow_length = 0; status = forms_receive (session_id, "trips_record", &trips_record_descr, NULL); /* * Obtain totals for the form. */ totals_record_descr.data_record = &totals_record; totals_record_descr.data_length = sizeof(totals_record); totals_record_descr.shadow_record = NULL; totals_record_descr.shadow_length = 0; status = forms_receive (session_id, "totals_record", &totals_record_descr, NULL); status = forms_enable (print_session, "prin_mrf.doc", NULL, "MRF_FORM", request_options); status = forms_send (print_session, "header_info_record", &header_info_record_descr, NULL); status = forms_send (print_session, "trips_record", &trips_record_descr, NULL); status = forms_send (print_session, "totals_record", &totals_record_descr, NULL); /* * Disable each session and exit. */ status = forms_disable (print_session, NULL); return 1; status = forms_disable (session_id, NULL); return 1; } /* * Routine: update_row * * Functional Description: * * Updates the information in the row of a trip record. The mileage * reimbursement amount is calculated from the number of miles travelled * (using 22½¢ per mile). * * Formal Parameters: * * trip-record - a pointer to the trip record * * Routine Value: * * none * */ void Forms_Callback update_row (Trip_Record *trip) { /* * Type cast trip miles to unsigned float, multiply by 22.5, and add .5 * to round off, and then recast to unsigned integer. */ trip->amount = (unsigned long)(((float)trip->miles * 22.5) + 0.5); return; } /* * Routine: do_totals * * Functional Description: * * Computes and updates the totals given the entire collection of trip * records. * * Formal Parameters: * * trips-record * total-miles * total-amount * total-tolls * form-total * * Routine Value: * * none * */ void Forms_Callback do_totals (Trip_Record (*trips)[TRIPRECORD], unsigned long *miles, unsigned long *amount, unsigned long *tolls, unsigned long *total) { unsigned n; /* * Initialize counters to zero */ *miles = *amount = *tolls = *total = 0; /* * For each entry with a nonzero mileage, accumulate the trips values into * the counters. */ for (n = 0; n < TRIPRECORD; n++) { if ((*trips)[n].miles != 0) { *miles = *miles + (*trips)[n].miles; *amount = *amount + (*trips)[n].amount; *tolls = *tolls + (*trips)[n].toll; *total = *total + (*trips)[n].subtotal; } } return; }