/* * PROGRAM forms$demo_tm.c */ /* * © Copyright 2005 Hewlett-Packard Development Company, L.P. * * Consistent with FAR 12.211 and 12.212, Commercial Computer Software, * Computer Software Documentation, and Technical Data for Commercial * Items are licensed to the U.S. Government under vendor's standard * commercial license. * */ /* This is the demo of the TM data type provided * with the DECforms product. * * AUTHOR: * * Hewlett-Packard Development Company. * * CREATION DATE: September, 1991 * * MODIFIED: */ #include #include #include #ifdef ultrix #include #endif #include #include /* * External functions */ char *getenv(); /* * Constants used in structure definitions */ #ifndef TRUE #define TRUE (1==1) #endif #ifndef FALSE #define FALSE (0==1) #endif #ifndef EXIT_SUCCESS #define EXIT_SUCCESS 0 #endif #ifndef EXIT_FAILURE #define EXIT_FAILURE 1 #endif /* * Global Variables / Structures */ #ifdef ultrix #define FORM_FILE_NAME "forms_demo_tm_form.form" #define INPUT_DEVICE_NAME "/dev/tty" #endif #ifdef vms #define FORM_FILE_NAME "forms$demo_tm_form" #define INPUT_DEVICE_NAME "SYS$INPUT" #endif Forms_Session_Id session_id; Forms_Status forms_status; exit_application(status) { /* * Clean up, Print ending message on console, and leave. * * This routine is called on normal and abnormal exits. * We *always* need to call forms_disable, otherwise the * terminal settings won't get restored. */ forms_status = forms_disable( session_id, /* As set by ENABLE */ NULL /* Request Options */ ); printf("DECforms Demo TM Application ending.\n"); exit( status ); } check_forms_status() { char msg_text[257]; /* * Check the parameter for success. If not success, print error * message and stop. */ if (forms_status != forms_s_normal && forms_status != forms_s_return_immed && forms_status != forms_s_converr) { /* * Null terminate the message text string. Then call a translation * routine to convert fims error number into message text. */ msg_text[256] = '\0'; forms_errormsg (forms_status, msg_text); fprintf(stderr, "\r\nForms error %d: %s\r\n", forms_status, msg_text); exit_application( EXIT_FAILURE ); } } send_time () /* * Send the current time to the form, using the TM data type. */ { /* * The Time record is sent to the form once to record the application start * time so it can be displayed in banners. */ struct time_record { Forms_Tm current_forms_tm; }; #define TIME_SIZE sizeof (struct time_record) struct time_record time_rec; time_t current_time; struct tm *current_tm; Forms_Record_Data record_data; /* * Ask the operating system for the current time. */ time(¤t_time); /* * Convert the local time into broken-down local time. */ current_tm = localtime (¤t_time); /* * Copy the broken-down local time into a record for DECforms. * Note that this logic avoids assuming that the tm structure * as implemented by this C compiler has the same length or offsets * as the DECforms implementation of TM. This is important for * portability because the ANSI C standard doesn't specify the * length of the tm structure or the offsets of the items in it. * Hence a new version of the C compiler might change these things * while remaining conformant with the ANSI standard, and your * program would fail when run with the new compiler if you depended * on the C compiler's tm matching the DECforms TM data type. * * By writing a series of assignment statements we ensure that no * matter how the C compiler defines the tm structure, the correct * data is placed in the expected place in the record message so * that the form manager can convert it to a DATETIME. * * If we were doing a forms_receive we would reverse each assignment * statement to fetch data from the DECforms TM record field into * a tm structure. In addition, if we wanted to make use of the * tm_wday or tm_yday fields we would call mktime to set them correctly * after the assignments. */ time_rec.current_forms_tm.tm_sec = current_tm->tm_sec; time_rec.current_forms_tm.tm_min = current_tm->tm_min; time_rec.current_forms_tm.tm_hour = current_tm->tm_hour; time_rec.current_forms_tm.tm_mday = current_tm->tm_mday; time_rec.current_forms_tm.tm_mon = current_tm->tm_mon; time_rec.current_forms_tm.tm_year = current_tm->tm_year; time_rec.current_forms_tm.tm_wday = current_tm->tm_wday; time_rec.current_forms_tm.tm_yday = current_tm->tm_yday; time_rec.current_forms_tm.tm_isdst = current_tm->tm_isdst; /* * Send the record to the form. */ record_data.data_record = (void *)&time_rec; record_data.data_length = TIME_SIZE; record_data.shadow_record = NULL; record_data.shadow_length = 0; forms_status = forms_send( session_id, /* session id */ "time_rec", /* record name in form */ &record_data, /* the record */ NULL); /* request options */ check_forms_status(); } main() { char *forms_examples_p = ""; static char empty[] = ""; char *form_file_name_p; char *device_name_string = INPUT_DEVICE_NAME; char *form_name_string = "forms_demo_tm_form"; Forms_Form_Object forms_demo_tm_form; Forms_Request_Options enable_options [2]; printf("DECforms Demo TM Application starting.\n"); /* * On Ultrix, if FORMS_EXAMPLES is set, then prefix it to the * file name of the form file. */ #ifdef ultrix forms_examples_p = getenv("FORMS_EXAMPLES"); #endif if (forms_examples_p == NULL) { forms_examples_p = empty; }; /* * Set up the strings pointing to the file name of the form file. */ form_file_name_p = (char *)malloc( sizeof(FORM_FILE_NAME) + 1 + strlen(forms_examples_p) ); if ( 0 == strlen( forms_examples_p ) ) { strcpy( form_file_name_p, FORM_FILE_NAME ); } else { strcpy( form_file_name_p, forms_examples_p ); strcat( form_file_name_p, "/" ); strcat( form_file_name_p, FORM_FILE_NAME ); }; /* * Initialize the DECforms form & check for errors. */ enable_options[0].option = forms_c_opt_form; enable_options[0].form.object = forms_demo_tm_form; enable_options[1].option = forms_c_opt_end; forms_status = forms_enable ( session_id, /* Session id is returned */ device_name_string, /* Name of terminal device */ form_file_name_p, /* Name of form file */ form_name_string, /* Name of form */ enable_options /* request options list */ ); check_forms_status(); free( (void *)form_file_name_p ); /* name isn't needed, free the memory */ /* * Send the time and wait for any response. */ send_time (); /* * Clean up, Print ending message on console, leave with success. */ exit_application(EXIT_SUCCESS); }