/* * Copyright (c) 1990, 1995 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 assumes no responsibility for the use or reliability of its * software on equipment which is not supplied by Digital. * * * Facility: tafr - track and field registration demo * * Abstract: This module contains the main driver and general purpose routines. * * Environment: OpenVMS * */ #include #include #include #include #include #include #ifdef vms #include #else #include #endif /* * Table of contents */ int main(); void pause_interface(); unsigned fill_filebox(); void check_status (); #ifdef vms unsigned vms_fill_filebox(); #else unsigned ultrix_fill_filebox(); #endif /* * Variables used by the Portable API request calls. */ Forms_Request_Options enable_options[2]; Forms_Session_Id session_id; Forms_Form_Object TAFR_FORM; Forms_Status status; /* * Platform dependent information. */ #ifdef vms #define device_name "SYS$OUTPUT" /* * VMS Descriptors */ typedef struct { unsigned short length; unsigned char dtype; unsigned char class; char *pointer; } Descriptor; #define _dx_Empty {0, DSC$K_DTYPE_T, DSC$K_CLASS_S, NULL} #else /* * Constants for ULTRIX */ #define device_name "/dev/tty" #define MAX_COMMAND_LENGTH 256 #define MAX_STRING_LENGTH 48 #endif /* * Routine: main * * Functional Description: * * Executive routine for the tafr program. This routine controls the high- * level execution which consists of enabling and disabling the form. All * user interaction takes place as a result of the enable response. The * enable request does not terminate until the user terminates the * interactive session. * * Formal Parameters: * * none (the argc and argv C parameters are not used by this program) * * Routine Value: * * true * */ int main () { char display_device[11]; /* Set up display device name for the Enable call */ strcpy (display_device, device_name); enable_options[0].option = forms_c_opt_form; enable_options[0].form.object = TAFR_FORM; enable_options[1].option = forms_c_opt_end; status = forms_enable (session_id, display_device, NULL, "TAFR_FORM", enable_options); check_status (status, "Enable"); /* * Disable the form */ status = forms_disable (session_id, NULL); check_status (status, "Disable"); } void check_status (Forms_Status status, char *request_name) { char msg_text[256]; Forms_Status disable_status; /* */ /* If request status is not normal then call forms_errormsg */ /* to translate fims error number into message text. */ /* */ forms_errormsg (status, msg_text); if ((status != forms_s_normal) && (status != forms_s_return_immed) && (status != forms_s_converr)) { /* * Disable the form */ disable_status = forms_disable (session_id, NULL); /* print out the fims error number */ fprintf(stderr, "%s FIMS error number is %d or in hex %x \n", request_name, status, status); /* print out the corresponding message text */ fprintf(stderr, "%d : %s", status, msg_text); if (disable_status != forms_s_normal) fprintf (stderr, "Failure disabling the form. Status is %d \n.", disable_status); exit (0); } } /* * Routine: pause_interface * * Functional Description: * * This procedural escape routine pauses for the specified number of * seconds. It is used as a "stub" for a function that, if actually * implemented, might take a significant length of time. This routine * could be used, for example, to display a "work in progress" box for * a specified period of time. * * Formal Parameters: * * none * * Routine Value: * * none * */ void pause_interface (delay) unsigned delay; { sleep (delay); return; } /* * Routine: fill_filebox * * * Functional Description: * * This jacket routine determines the platform and calls the appropriate * fill_filebox routine. * * Formal Parameters: * * filter (by ref) - A file specification which may consist of directory spec, * file spec, file type and wildcards. * file_array (by ref) - An array buffer to store all the file names which match the * criteria specified by the filter. * string_length (by value) - Maximum length of the file filter. * array_length (by value) - Maximum length of the array buffer. * * Routine Value: * * file_count - number of files that match the given filter. * */ unsigned fill_filebox ( char *filter, char *file_array, int string_length, int array_length) { unsigned file_count; #ifdef vms file_count = vms_fill_filebox (filter, file_array, string_length, array_length); #else file_count = ultrix_fill_filebox (filter, file_array, string_length, array_length); #endif return file_count; } #ifdef vms /* * Routine: vms_fill_filebox * * * Functional Description: * * This VMS specific routine sets up VMS descriptors and make a call to Lib$Find_File * using the given filter and load all the file names satisfying the filter criteria * into the array buffer. * * Formal Parameters: * * filter (by ref) - A file specification which may consist of directory spec, * file spec, file type and wildcards. * file_array (by ref) - An array buffer to store all the file names which match the * criteria specified by the filter. * string_length (by value) - Maximum length of the file filter. * array_length (by value) - Maximum length of the array buffer. * * Routine Value: * * n - number of files that match the given filter. * */ unsigned vms_fill_filebox ( char *filter, char *file_array, int string_length, int array_length) { unsigned n, ok, context = 0; Descriptor result_dx = _dx_Empty; Descriptor filter_dx = _dx_Empty; char *ptr; /* Initialize the file array buffer with blank spaces */ memset (file_array, ' ', string_length * array_length); /* Set up VMS descriptors for Lib$Find_File */ filter_dx.length = string_length; filter_dx.pointer = filter; result_dx.length = string_length; result_dx.pointer = malloc (string_length); /* Locate all files which matches the given filter criteria */ /* and load their names into the file array buffer. */ for (n = 0; n < array_length; n++) { ok = lib$find_file (&filter_dx, &result_dx, &context); /* VMS status divisible by 2 indicates failure. */ /* Bail out if this is the case. */ if (ok % 2 == 0) break; ptr = file_array + (n * string_length); strncpy (ptr, result_dx.pointer, string_length); } /* clean up before we return */ lib$find_file_end (&context); free (result_dx.pointer); return n; } #endif #ifndef vms /* * Routine: ultrix_fill_filebox * * * Functional Description: * * This ULTRIX specific routine sets up a pipe to execute a "ls" command with the given * filter and stores the result listing into the array buffer. * * Formal Parameters: * * filter (by ref) - A file specification which may consist of directory spec, * file spec, file type and wildcards. * file_array (by ref) - An array buffer to store all the file names which match the * criteria specified by the filter. * string_length (by value) - Maximum length of the file filter. * array_length (by value) - Maximum length of the array buffer. * * Routine Value: * * n - number of files that match the given filter. * */ unsigned ultrix_fill_filebox ( char *filter, char *file_array, int string_length, int array_length) { char buf[MAX_STRING_LENGTH]; char *file_array_ptr; char *command_string; FILE *popen_ptr; size_t trim_blanks; int n; /* Initialize variables */ command_string = (char *) malloc (MAX_COMMAND_LENGTH); memset (file_array, ' ', string_length * array_length); n = 0; /* Construct the command string to be executed */ strcpy (command_string, "/bin/ls "); trim_blanks = strcspn (filter, " "); strncat (command_string, filter, trim_blanks); /* Establish a pipe for reading the result of the ls command */ popen_ptr = popen (command_string, "r"); if (popen_ptr == NULL) return 0; /* Locate all files which matches the given filter criteria */ /* and load their names into the file array buffer. */ while ( fscanf(popen_ptr, "%48[^\n]", buf) != EOF ) { fgetc (popen_ptr); file_array_ptr = file_array + (n++ * string_length); strcpy(file_array_ptr, buf); *buf = 0; } /* clean up before we leave */ pclose (popen_ptr); free (command_string); return n; } #endif