argv@island.uu.net (Dan Heller) (06/30/89)
Submitted-by: Jim Westervelt <westerve@osiris.cso.uiuc.edu> Posting-number: Volume 4, Issue 41 Archive-name: xgen/part03 #! /bin/sh # This is a shell archive. Remove anything before this line, then feed it # into a shell via "sh file" or similar. To overwrite existing files, # type "sh file -c". # The tool that generated this appeared in the comp.sources.unix newsgroup; # send mail to comp-sources-unix@uunet.uu.net if you want that tool. # If this archive is complete, you will see the following message at the end: # "End of shell archive." # Contents: hash_env.c hash_help.c hash_shell_address.c # hash_shell_descrip.c help.c main.c parse_applica.c # parse_resources.c parse_shell.c spreadsheet.c # Wrapped by argv@island on Thu Jun 29 19:27:53 1989 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f 'hash_env.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'hash_env.c'\" else echo shar: Extracting \"'hash_env.c'\" \(1141 characters\) sed "s/^X//" >'hash_env.c' <<'END_OF_FILE' X#define MAX_NUM_ENVS 20 X#include <stdio.h> X#include <X11/IntrinsicP.h> X#include <X11/Intrinsic.h> X#include <X11/CompositeP.h> X#include <X11/CommandP.h> X#include <X11/LabelP.h> X#include <X11/Box.h> X#include <X11/StringDefs.h> X#include <X11/Shell.h> X#include <X11/Viewport.h> X#include <X11/Form.h> X#include <X11/Core.h> X#include <X11/VPaned.h> X#include "application.h" X Xstatic struct _env env[MAX_NUM_ENVS]; X Xenter_env_shells( name, initial_shell_header) Xchar *name; Xstruct env_shell *initial_shell_header; X X{ X X static int i = 0; X int key; X X if( i == 0 ) X { X for ( i=0 ; i<MAX_NUM_ENVS ; i++ ) X { X env[i].initial_shells = NULL; X } X } X X key = ((*name) * *(name+1))%MAX_NUM_ENVS; X X while( env[key].initial_shells != NULL ) X key = ++key % MAX_NUM_ENVS ; X X env[key].initial_shells = initial_shell_header ; X X X env[key].name = (char *)XtMalloc((strlen(name) + 1)); X strcpy( env[key].name, name); X X X} X Xstruct env_shell *get_env_shells(name) Xchar *name; X X{ X int key; X key = ((*name) * *(name+1))%MAX_NUM_ENVS; X X while( env[key].initial_shells != NULL X && strcmp(env[key].name, name) != 0) X key++; X X X return(env[key].initial_shells); X X} X X X END_OF_FILE if test 1141 -ne `wc -c <'hash_env.c'`; then echo shar: \"'hash_env.c'\" unpacked with wrong size! fi # end of 'hash_env.c' fi if test -f 'hash_help.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'hash_help.c'\" else echo shar: Extracting \"'hash_help.c'\" \(1540 characters\) sed "s/^X//" >'hash_help.c' <<'END_OF_FILE' X#define MAX_NUM_WIDGETS 200 X#include <stdio.h> X#include <X11/IntrinsicP.h> X#include <X11/Intrinsic.h> X#include <X11/CompositeP.h> X#include <X11/CommandP.h> X#include <X11/LabelP.h> X#include <X11/Box.h> X#include <X11/StringDefs.h> X#include <X11/Shell.h> X#include <X11/Viewport.h> X#include <X11/Form.h> X#include <X11/Core.h> X#include <X11/VPaned.h> X#include "application.h" X Xextern char *string[]; X Xstatic struct _widget_help widget_help[ MAX_NUM_WIDGETS ]; X Xenter_hash_help( widget_ptr, help_msg ) XWidget widget_ptr; Xchar *help_msg; X X{ X X struct _widget_help *help_item; X static int i = 0; X int key; X X if( i == 0) X { X for ( i =0; i<MAX_NUM_WIDGETS; i++) X { X widget_help[i].widget_ptr= NULL; X } X } X X if( help_msg == NULL ) X return; X X key = ((long)(widget_ptr))%MAX_NUM_WIDGETS; X X while( widget_help[key].widget_ptr != NULL) X key = ++key%MAX_NUM_WIDGETS; X widget_help[key].widget_ptr = widget_ptr; X /* printf(" help_msg %s\n",help_msg); X*/ X widget_help[key].help_msg = (char *)malloc( X (strlen(help_msg)+1) * sizeof( char )); X X strcpy(widget_help[key].help_msg , help_msg); X X return; X} X X Xchar *get_hash_help(widget_ptr) XWidget widget_ptr; X{ X X int key; X X key = ((long)widget_ptr)%MAX_NUM_WIDGETS; X X /*printf(" %d key\n", key); X X printf( "widget_ptr %d widget_he %d\n", widget_ptr, widget_help[key].widget_ptr); X*/ X while(widget_ptr != widget_help[key].widget_ptr) X { X key++; X if( key > MAX_NUM_WIDGETS ) X return(NULL); X } X /*printf("msg %s\n", widget_help[key].help_msg); X*/ X X X return(widget_help[key].help_msg); X} END_OF_FILE if test 1540 -ne `wc -c <'hash_help.c'`; then echo shar: \"'hash_help.c'\" unpacked with wrong size! fi # end of 'hash_help.c' fi if test -f 'hash_shell_address.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'hash_shell_address.c'\" else echo shar: Extracting \"'hash_shell_address.c'\" \(1625 characters\) sed "s/^X//" >'hash_shell_address.c' <<'END_OF_FILE' X#define MAX_NUM_SHELLS 50 X#include <stdio.h> X#include <X11/IntrinsicP.h> X#include <X11/Intrinsic.h> X#include <X11/CompositeP.h> X#include <X11/CommandP.h> X#include <X11/LabelP.h> X#include <X11/Box.h> X#include <X11/StringDefs.h> X#include <X11/Shell.h> X#include <X11/Viewport.h> X#include <X11/Form.h> X#include <X11/Core.h> X#include <X11/VPaned.h> X#include "application.h" X Xstatic struct _shell_address shell_address[MAX_NUM_SHELLS]; X Xenter_shell_address( widget_ptr, name) XWidget widget_ptr; Xchar *name; X X{ X X static int i = 0; X int key; X X if( i == 0 ) X { X for ( i=0 ; i<MAX_NUM_SHELLS ; i++ ) X { X shell_address[i].name = NULL; X } X } X X X key = ((*name) * *(name+1))%MAX_NUM_SHELLS; X X X while( shell_address[key].name != NULL && X *(shell_address[key].name) != '!') X key = ++key%MAX_NUM_SHELLS; X X X shell_address[key].widget_ptr = widget_ptr; X X X shell_address[key].name = (char *)malloc( X (strlen(name)+1) * sizeof( char )); X X strcpy( shell_address[key].name, name); X X} X XWidget get_shell_address(name) Xchar *name; X X{ X int key; X X key = ((*name) * *(name+1))%MAX_NUM_SHELLS; X X X X while( shell_address[key].widget_ptr != NULL X && strcmp(shell_address[key].name, name) != 0) X key++; X X X return(shell_address[key].widget_ptr); X} X Xremove_shell_address(name) Xchar *name; X{ X int key; X X key = ((*name * *(name+1)))%MAX_NUM_SHELLS; X X while( shell_address[key].widget_ptr != NULL && X strcmp(shell_address[key].name, name) != 0) X key++; X X if(shell_address[key].widget_ptr == NULL) X { X fprintf(stderr," Shell %s not found: Not removed\n", X name); X return(0); X } X X *(shell_address[key].name) = '!'; X X return(1); X X X} END_OF_FILE if test 1625 -ne `wc -c <'hash_shell_address.c'`; then echo shar: \"'hash_shell_address.c'\" unpacked with wrong size! fi # end of 'hash_shell_address.c' fi if test -f 'hash_shell_descrip.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'hash_shell_descrip.c'\" else echo shar: Extracting \"'hash_shell_descrip.c'\" \(1095 characters\) sed "s/^X//" >'hash_shell_descrip.c' <<'END_OF_FILE' X#define MAX_NUM_SHELLS 50 X#include <stdio.h> X#include <X11/IntrinsicP.h> X#include <X11/Intrinsic.h> X#include <X11/CompositeP.h> X#include <X11/CommandP.h> X#include <X11/LabelP.h> X#include <X11/Box.h> X#include <X11/StringDefs.h> X#include <X11/Shell.h> X#include <X11/Viewport.h> X#include <X11/Form.h> X#include <X11/Core.h> X#include <X11/VPaned.h> X#include "application.h" X Xstatic struct shell *app_shell[MAX_NUM_SHELLS]; X Xenter_shell_descrip( pres_shell) Xstruct shell *pres_shell; X{ X X static int i = 0; X int key; X char *name; X X if( i == 0 ) X { X for ( i=0 ; i<MAX_NUM_SHELLS ; i++ ) X { X app_shell[i] = NULL; X } X } X X name = pres_shell->name; X X key = ((*name) * *(name+1))%MAX_NUM_SHELLS; X X X while( app_shell[key] != NULL ) X key = ++key%MAX_NUM_SHELLS; X X app_shell[key] = pres_shell; X X} X Xstruct shell *get_shell(name) Xchar *name; X X{ X int key; X X key = ((*name) * *(name+1))%MAX_NUM_SHELLS; X X X while( strcmp(app_shell[key]->name, name) != 0) X X { X key++; X if( app_shell[key] == NULL ) X { X fprintf(stderr, "shell %s: Not found.\n", name ); X return( NULL ); X } X } X X return(app_shell[key]); X} END_OF_FILE if test 1095 -ne `wc -c <'hash_shell_descrip.c'`; then echo shar: \"'hash_shell_descrip.c'\" unpacked with wrong size! fi # end of 'hash_shell_descrip.c' fi if test -f 'help.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'help.c'\" else echo shar: Extracting \"'help.c'\" \(3333 characters\) sed "s/^X//" >'help.c' <<'END_OF_FILE' X#include <stdio.h> X#include <X11/IntrinsicP.h> X#include <X11/Intrinsic.h> X#include <X11/StringDefs.h> X#include <X11/Shell.h> X#include <X11/Core.h> X#include <X11/Text.h> X#include <X11/AsciiText.h> X#include <X11/AsciiTextP.h> X#include "application.h" X Xextern int max_help_msg_width; Xextern int max_help_msg_height; Xextern int max_error_msg_width; Xextern int max_error_msg_height; Xextern XFontStruct *help_msg_font; Xextern XFontStruct *error_msg_font; Xextern Widget help_msg_widget; Xextern Widget error_msg_widget; Xextern Widget label_error_widget; Xextern Widget label_help_widget; X X Xvoid Xpopup_help(); X Xvoid Xbutton_help( w, closure, call_data) XWidget w; Xcaddr_t closure; Xcaddr_t call_data; X{ X popup_help( closure ); X} X Xvoid Xhelp(w, event, params, num_params) XWidget w; XXEvent *event; XString *params; XCardinal *num_params; X{ X char *help_string; X char *get_hash_help(); X X help_string = get_hash_help(w); X X if( help_string == NULL ) X help_string = "Sorry, I can't find any help for this item"; X X popup_help( help_string); X} X X/*These routines will resize the message according to the */ X/*string that will be displayed and replace the old string by */ X/*the new one and pop the corresponding msgboard to the screen */ X Xvoid Xpopup_help(string) Xchar *string; X{ X int width; X int i = 0; X int char_height, X height; X Arg args[15]; X XtTextBlock text; X static char *old_string = ""; X Widget help_widget; X Widget get_shell_address(); X X if( string == NULL ) X return; X X help_widget = get_shell_address("help"); X X width = XTextWidth(help_msg_font, string, strlen(string)); X X char_height = help_msg_font->ascent + help_msg_font->descent; X X height = (width/max_help_msg_width +2)* char_height; X X if (width > max_help_msg_width) X { X width = max_help_msg_width; X XtSetArg(args[i], XtNwidth, X max_help_msg_width); X i++; X XtSetArg(args[i], XtNheight, height+2); X i++; X } X else X { X XtSetArg(args[i], XtNwidth, width+2); X i++; X XtSetArg( args[i], XtNheight, 2*char_height +2); X i++; X X } X X XtSetValues( help_msg_widget, args, i); X X XtSetValues( label_help_widget, args, 1); X X text.firstPos = 0; X text.ptr = string; X text.length = strlen(string); X X popup(help_widget, "help"); X X XtTextReplace( help_msg_widget, 0, strlen(old_string), &text); X X old_string = string; X} X X Xvoid Xpopup_error(string) Xchar *string; X{ X int width; X int i = 0; X int char_height, X height; X Arg args[15]; X XtTextBlock text; X static char *old_string = ""; X Widget error_widget; X Widget get_shell_address(); X X if( string == NULL ) X return; X X error_widget = get_shell_address("error"); X X width = XTextWidth(error_msg_font, string, strlen(string)); X X char_height = error_msg_font->ascent + error_msg_font->descent; X X height = (width/max_error_msg_width +2)* char_height; X X if (width > max_error_msg_width) X { X width = max_error_msg_width; X XtSetArg(args[i], XtNwidth, X max_error_msg_width); X i++; X XtSetArg(args[i], XtNheight, height+2); X i++; X } X else X { X XtSetArg(args[i], XtNwidth, width+2); X i++; X XtSetArg( args[i], XtNheight, 2*char_height +2); X i++; X X } X X XtSetValues( error_msg_widget, args, i); X X XtSetValues( label_error_widget, args, 1); X X text.firstPos = 0; X text.ptr = string; X text.length = strlen(string); X X popup(error_widget, "error"); X X XtTextReplace( error_msg_widget, 0, strlen(old_string), &text); X X old_string = string; X} END_OF_FILE if test 3333 -ne `wc -c <'help.c'`; then echo shar: \"'help.c'\" unpacked with wrong size! fi # end of 'help.c' fi if test -f 'main.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'main.c'\" else echo shar: Extracting \"'main.c'\" \(1272 characters\) sed "s/^X//" >'main.c' <<'END_OF_FILE' X#include <stdio.h> X#include <X11/Intrinsic.h> X#include <X11/Shell.h> X#include "application.h" X XWidget top_level; X Xextern void get_env(); Xextern void help(); X XXtTranslations input_text_translations; X X X Xmain(argc, argv) Xint argc; Xchar **argv; X X{ X static XtActionsRec actionlist[] = X { X {"Help", help}, X }; X X struct shell *help_board; X struct shell *error_board; X struct shell *get_shell(); X XtTranslations parse_spreadsheet_transl(); X X X /* Initialize the Toolkit and the resource manager */ X top_level = XtInitialize("", "", NULL ,NULL, &argc, argv); X X X XtAddActions( actionlist, 1); X X X /*parse translations at initialization time */ X input_text_translations = parse_spreadsheet_transl(); X X /*parse application script*/ X parse_app( argv[1] ); X X /*create help shell*/ X X help_board = get_shell("help"); X X if( help_board == NULL ) X { X fprintf(stderr, " Error: description of msgboard \"help\" is not provided\n"); X exit(-1); X } X create_msgboard(help_board); X X error_board = get_shell("error"); X X if( error_board == NULL ) X { X fprintf(stderr, " Error: description of msgboard \"error\" is not provided\n"); X exit(-1); X } X create_msgboard(error_board); X X X /*bring to the screen the environment called top level */ X get_env( top_level, "top level" ); X X XtMainLoop(); X X} X X END_OF_FILE if test 1272 -ne `wc -c <'main.c'`; then echo shar: \"'main.c'\" unpacked with wrong size! fi # end of 'main.c' fi if test -f 'parse_applica.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'parse_applica.c'\" else echo shar: Extracting \"'parse_applica.c'\" \(2875 characters\) sed "s/^X//" >'parse_applica.c' <<'END_OF_FILE' X#include <stdio.h> X#include <ctype.h> X#include "application.h" X Xparse_app(file) Xchar *file; X X{ X FILE *fp1, *fopen(); X char buffer[STR_LEN] ; X char *bptr ; X char type[STR_LEN], name[STR_LEN]; X char string1[STR_LEN], X string2[STR_LEN]; X struct env_shell *header1, X *pres_shell, X *old_shell; X int C; X struct shell *app_shell; X struct shell *parse_shell(); X X X /* open file input in command line*/ X if (NULL == (fp1 = fopen( file, "r"))) X { X fprintf(stderr, "Error: Can't find input file %s\n", file) ; X exit(-1) ; X } X X for(;;) X { X get_string(fp1, type, NULL, STR_LEN) ; X X /* if the type declaration is environment then X * parse the environment X */ X if (! strcmp(type, "environment") == 0) X { X fprintf(stderr,"Error: expecting <environment>, got <%s>\n", type) ; X exit(-1) ; X } X X get_string(fp1, name, NULL, STR_LEN) ; X Xstart:/* parse env options below */ X X get_symbol(fp1, &C) ; X X if ( C != '{' ) X { X ungetc( C, fp1); X X get_string(fp1, string1, ':', STR_LEN) ; X X get_symbol(fp1, &C) ; X X /*check the validity of the env options*/ X if( strcmp(string1, "initialshells")) X { X fprintf(stderr, "Error: No such option <%s> for environment <%s>. Ignored.\n", X string1, name); X goto start; X } X X get_string(fp1, buffer, NULL, STR_LEN) ; X X bptr = buffer ; X X /* Get rid of leading spaces */ X while (*bptr != NULL && isspace(*bptr)) X bptr++ ; X header1 = (struct env_shell *)malloc( X sizeof( struct env_shell)); X X if (1 != sscanf(bptr, "%s", header1->name)) X { X fprintf(stderr, "Error parsing initialshells for <%s>\n", X name) ; X exit(-1) ; X } X X old_shell = header1; X X for(;;) X { X /* Read past word already read */ X while (*bptr != NULL && ! isspace(*bptr)) X bptr++ ; X /* Get rid of leading spaces */ X while (*bptr != NULL && isspace(*bptr)) X bptr++ ; X X if (1 != sscanf(bptr, "%s", string2)) X break ; X X /* create a linked list with the names X * of the initial shells X */ X pres_shell = (struct env_shell *)malloc( X sizeof( struct env_shell)); X X strcpy( pres_shell->name, string2); X X X old_shell->next = pres_shell; X old_shell = pres_shell; X } X old_shell->next = NULL; X X goto start; X } X /*parse the environment shells*/ X X while(1) X { X /* do the parsing until the closing bracket is X * encountered X */ X get_symbol(fp1, &C) ; X X if( C == '}' ) X { X /* old_shell->next = NULL;*/ X break; X } X X ungetc( C, fp1); X X /* parse the shell and enter the shell address X * in the shell hash tables X */ X X app_shell = parse_shell( fp1 ); X X enter_shell_descrip( app_shell, app_shell->name); X } X X X /* enter the initial shells of the environment in the hash X * table X */ X enter_env_shells(name, header1); X X /* Check for EOF, which is appropriate here */ X if (check_eof(fp1)) X break ; X } X X fclose(fp1); X} END_OF_FILE if test 2875 -ne `wc -c <'parse_applica.c'`; then echo shar: \"'parse_applica.c'\" unpacked with wrong size! fi # end of 'parse_applica.c' fi if test -f 'parse_resources.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'parse_resources.c'\" else echo shar: Extracting \"'parse_resources.c'\" \(1871 characters\) sed "s/^X//" >'parse_resources.c' <<'END_OF_FILE' X#include <stdio.h> X#include "application.h" X Xstruct resource *parse_resources( fp1, shell_label, label) XFILE *fp1; Xchar *shell_label; Xchar *label; X{ X char resource_value[1024]; X char *temp; X X struct resource *header, X *pres_resource, X *prev_resource; X X int C ; X int count = 0; X X /* start a linked list of the widget resources */ X header = (struct resource *)malloc(sizeof( X struct resource)); X strcpy( header->name, "label"); X X /*first resource is the label of the widget*/ X header->value = ( char *)malloc( X (strlen(label) +1)*sizeof(char)); X X strcpy( header->value, label); X X/* fprintf(stderr, "parsing object %s", header->value); */ X /* initialize the linked list */ X pres_resource = header; X prev_resource = header; X X while(1) X { X get_symbol(fp1, &C) ; X X /* if the option declaration is closed exit loop */ X if (C == ';'|| C == '(') X { X ungetc(C, fp1); X break; X } X X ungetc(C, fp1); X X /* otherwise add a new data resource to the list */ X pres_resource = (struct resource *)malloc(sizeof( X struct resource)); X X prev_resource->next = pres_resource; X X /* read and resource name */ X get_string(fp1, pres_resource->name, ':', STR_LEN) ; X X/* fprintf(stderr,"parsing option %s\n", pres_resource->name);*/ X X temp = resource_value; X X /* read colon */ X get_symbol(fp1, &C) ; X if( C != ':' ) X { X fprintf(stderr, "Syntax error in shell \"%s\" in object \"%s\" declaration\n", X shell_label, label); X exit(-1); X } X get_string(fp1, temp, ';', 1024) ; X X pres_resource->value = ( char *)malloc( X (strlen( resource_value)+1) * sizeof(char)); X strcpy(pres_resource->value, resource_value); X X/* fprintf(stderr,"option val %s\n", pres_resource->value);*/ X X prev_resource = pres_resource; X X } X /*close linked list*/ X/* fprintf(stderr,"option val %s\n", pres_resource->value);*/ X X pres_resource->next = NULL; X X X return(header); X} END_OF_FILE if test 1871 -ne `wc -c <'parse_resources.c'`; then echo shar: \"'parse_resources.c'\" unpacked with wrong size! fi # end of 'parse_resources.c' fi if test -f 'parse_shell.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'parse_shell.c'\" else echo shar: Extracting \"'parse_shell.c'\" \(1879 characters\) sed "s/^X//" >'parse_shell.c' <<'END_OF_FILE' X#include <stdio.h> X#include "application.h" X Xstruct shell *help_widget; X Xstruct shell *parse_shell(fp1) XFILE *fp1; X{ X struct shell *header, *pres_shell, *prev_shell; X struct widget *pres_widget, *prev_widget; X struct resource *parse_resources(); X int count=0; X char string[STR_LEN]; X char label[STR_LEN]; X char shell_label[STR_LEN]; X char *label_ptr; X int C ; X X *label = NULL ; X X /*start a linked list to store the shell description*/ X header = (struct shell *)malloc(sizeof( struct shell)); X X get_string(fp1, header->type, NULL, STR_LEN) ; X X /* get the name of the shell*/ X get_string(fp1, header->name, NULL, STR_LEN) ; X strncpy(shell_label, header->name, STR_LEN) ; X X/*fprintf(stderr,"parsing shell %s\n", shell_label);*/ X X /* parse the shell options */ X header->resources = parse_resources(fp1, shell_label, label); X X get_symbol(fp1, &C) ; X if( C != '(' ) X { X fprintf(stderr,"Syntax error in shell %s, \"(\" expected", X shell_label); X exit(-1); X } X X X /* parse the shell's components (widgets) */ X while(1) X { X pres_widget = (struct widget *)malloc(sizeof( X struct widget)); X /* get widget type */ X get_string(fp1, pres_widget->type, NULL, STR_LEN) ; X X /* get widget name */ X get_string(fp1, label, NULL, STR_LEN) ; X X /* parse the widget resources */ X pres_widget->resources = parse_resources( fp1, X shell_label, label); X X get_symbol(fp1, &C) ; X if( C != ';' ) X { X fprintf(stderr,"Erro: syntax in shell \"%s\" next to \"%s\" \"%s\" \n", X shell_label, pres_widget->type, label); X exit(-1); X } X X if( count > 0) X prev_widget->next_widget = pres_widget; X else X { X header->child = pres_widget; X count = 1; X } X X prev_widget = pres_widget; X X /* if the next character is a closing parenthesis return X * else loop again X */ X X get_symbol(fp1, &C) ; X X if(C == ')') X break; X else X ungetc(C, fp1); X } X X return( header); X} END_OF_FILE if test 1879 -ne `wc -c <'parse_shell.c'`; then echo shar: \"'parse_shell.c'\" unpacked with wrong size! fi # end of 'parse_shell.c' fi if test -f 'spreadsheet.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'spreadsheet.c'\" else echo shar: Extracting \"'spreadsheet.c'\" \(20931 characters\) sed "s/^X//" >'spreadsheet.c' <<'END_OF_FILE' X#define MAX_NUM_ARGS 20 X#define MAX_NUMBER_COLUMNS 10 X#define SIZE_OF_INPUT_STRING 50 X#define SIZE_OF_SCROLL_STRING 1000 X#define MAX_NUM_SPREADSHEETS 20 X#include <stdio.h> X#include <X11/IntrinsicP.h> X#include <X11/Intrinsic.h> X#include <X11/CompositeP.h> X#include <X11/CommandP.h> X#include <X11/LabelP.h> X#include <X11/StringDefs.h> X#include <X11/Shell.h> X#include <X11/Form.h> X#include <X11/Core.h> X#include <X11/Viewport.h> X#include <X11/VPaned.h> X#include <X11/Text.h> X#include <X11/AsciiText.h> X#include <X11/AsciiTextP.h> X X#include "application.h" X Xvoid nothing() X{ X return; X} X Xextern Widget top_level; X Xstatic char space_string[] = " "; Xextern XtTranslations input_text_translations; Xstatic XtTranslations scroll_text_translations; Xstatic XtTranslations spread_input_translations; X X Xstruct _spreadsheet { X Widget input_text; X Widget scroll_text; X int scrolltext_width; /* number of characters */ X int column_width[MAX_NUMBER_COLUMNS]; X int number_of_columns; X char input_string[SIZE_OF_INPUT_STRING]; X char scroll_string[SIZE_OF_SCROLL_STRING]; X long cursor_position; X int pres_column; X int total_width; X}; X Xstruct _spreadsheet_info { X Widget widget_ptr; X struct _spreadsheet *spreadsheet; X}; X Xstatic struct _spreadsheet_info Xspreadsheet_info[MAX_NUM_SPREADSHEETS]; Xvoid check_length(); X Xvoid bell() X{ X XBell( XtDisplay(top_level), 50 ); X} X XXtTranslations parse_spreadsheet_transl() X{ X X void copy_to_scroll(); X void update_cursor_position(); X X static XtActionsRec actionlist[] = X { X {"Nothing", nothing}, X {"Bell", bell}, X {"Copy_To_Scroll", copy_to_scroll}, X {"Update_Cursor_Position", update_cursor_position} X }; X X X static char Input_Text_Translations[] = X "Ctrl<Key>N: Bell() \n\ X <Key>0xff54: Bell() \n\ X Ctrl<Key>P: Bell() \n\ X <Key>0xff52: Bell() \n\ X Ctrl<Key>V: Bell() \n\ X Meta<Key>V: Bell() \n\ X Ctrl<Key>Z: Bell() \n\ X Meta<Key>Z: Bell() \n\ X Ctrl<Key>J: Bell() \n\ X <Key>0xff0a: Bell() \n\ X Ctrl<Key>O: Bell() \n\ X Ctrl<Key>M: Bell() \n\ X Ctrl<Key>L: Bell() \n\ X Meta<Key>I: Bell() \n\ X <Key>0xff0d: Bell() \n\ X Shift<Btn1Up>: Help()"; X X static char Spread_Input_Translations[] = X "<Key>0xff0d: Copy_To_Scroll()"; X X static char Scroll_Text_Translations[] = X "Ctrl<Key>N: Update_Cursor_Position(3)\n\ X Ctrl<Key>P: Update_Cursor_Position(4)\n\ X Ctrl<Key>F: Update_Cursor_Position(1)\n\ X Ctrl<Key>B: Update_Cursor_Position(2)\n\ X Button1<PtrMoved>: extend-adjust() \n\ X Button3<PtrMoved>: extend-adjust() \n\ X <BtnDown>: Nothing()\n\ X <Key>: Nothing()\n\ X Shift<Key>: Nothing()"; X X X input_text_translations = XtParseTranslationTable( X Input_Text_Translations ); X X scroll_text_translations = XtParseTranslationTable( X Scroll_Text_Translations ); X X spread_input_translations = XtParseTranslationTable( X Spread_Input_Translations ); X X XtAddActions( actionlist, 4); X X return( input_text_translations); X} X XWidget create_spreadsheet( resources , outer_form, Xprev_widget, pres_cmd_arg ) Xstruct resource *resources; XWidget outer_form; XWidget prev_widget; Xstruct _rec_cmd_line_arg **pres_cmd_arg; X{ X X Widget label, X label2, X form, X form2, X vpane; X X struct resource *pres_resource; X X Arg label_args[MAX_NUM_ARGS]; X Arg label2_args[MAX_NUM_ARGS]; X Arg scroll_args[MAX_NUM_ARGS]; X Arg vpane_args[MAX_NUM_ARGS]; X Arg form_args[MAX_NUM_ARGS]; X Arg text_args[MAX_NUM_ARGS]; X Arg args[MAX_NUM_ARGS]; X XFontStruct *font; X char string[STR_LEN]; X char *temp, *label_ptr, *number; X char *column_label; X char scrollspace_label[STR_LEN]; X int label_length, X number_length, X leading_spaces, X trailing_spaces; X int num_label_args = 0, X num_label2_args = 0, X num_vpane_args = 0, X num_scroll_args = 0, X num_form_args = 0, X num_text_args = 0, X num_args = 0; X int max_column_width = 0; X int column, X pixel; X X char *help_msg = NULL; X X struct _spreadsheet *spreadsheet; X X struct _grouped_arg *pres_grouped_arg, X *prev_grouped_arg; X X *pres_cmd_arg = (struct _rec_cmd_line_arg *)( X malloc(sizeof(struct _rec_cmd_line_arg))); X X spreadsheet = (struct _spreadsheet *)malloc( sizeof( struct _spreadsheet )); X X *(spreadsheet->scroll_string) = '\0'; X *(spreadsheet->input_string) = '\0'; X X spreadsheet->scrolltext_width = 0; X X pres_resource = resources; X X X while( pres_resource != NULL ) X { X if( !strcmp( pres_resource->name, "labelbackground") ) X { X pixel = get_pixel( pres_resource->value ); X XtSetArg( label_args[num_label_args], XtNbackground, X pixel ); X num_label_args++; X XtSetArg( form_args[num_form_args], XtNbackground, X pixel ); X num_form_args++; X goto next; X } X X X if( !strcmp( pres_resource->name, "labelforeground") ) X { X pixel = get_pixel( pres_resource->value ); X XtSetArg( label_args[num_label_args], XtNforeground, X pixel ); X num_label_args++; X goto next; X } X X if( !strcmp( pres_resource->name, "labelfont" ) ) X { X font = XLoadQueryFont( XtDisplay(top_level), X pres_resource->value ); X XtSetArg( label_args[num_label_args], XtNfont, X font); X num_label_args++; X goto next; X } X X if( !strcmp( pres_resource->name, "label" )) X { X XtSetArg( label_args[num_label_args], XtNlabel, X pres_resource->value ); X num_label_args++; X goto next; X } X X X if( !strcmp(pres_resource->name, "textbackground") ) X { X pixel = get_pixel( pres_resource->value ); X XtSetArg( text_args[num_text_args], XtNbackground, X pixel); X num_text_args++; X goto next; X } X X if( !strcmp(pres_resource->name, "textfont") ) X { X font = XLoadQueryFont( XtDisplay(top_level), X pres_resource->value ); X XtSetArg( text_args[num_text_args], XtNfont, X font); X num_text_args++; X goto next; X } X X if( !strcmp( pres_resource->name, "textforeground") ) X { X pixel = get_pixel( pres_resource->value ); X XtSetArg( text_args[num_text_args], XtNforeground, X pixel ); X num_text_args++; X goto next; X } X X if( !strcmp(pres_resource->name, "titlebackground") ) X { X pixel = get_pixel( pres_resource->value ); X XtSetArg( label2_args[num_label2_args], XtNbackground, X pixel); X num_label2_args++; X goto next; X } X X /* if( !strcmp(pres_resource->name, "titlefont") ) X { X font = XLoadQueryFont( XtDisplay(top_level), X pres_resource->value ); X XtSetArg( label2_args[num_label2_args], XtNfont, X font); num_label2_args++; X goto next; X }*/ X X if( !strcmp( pres_resource->name, "titleforeground") ) X { X pixel = get_pixel( pres_resource->value ); X XtSetArg( label2_args[num_label2_args], XtNforeground, X pixel ); X num_label2_args++; X goto next; X } X X X if( !strcmp( pres_resource->name, "scrollheight") ) X { X XtSetArg( scroll_args[num_scroll_args], XtNheight, X atoi(pres_resource->value) ); X num_scroll_args++; X goto next; X } X X if( !strcmp( pres_resource->name, "scrollbackground" )) X { X pixel = get_pixel( pres_resource->value ); X XtSetArg( scroll_args[num_scroll_args], XtNbackground, X pixel ); X num_scroll_args++; X goto next; X } X X if( !strcmp( pres_resource->name, "scrollforeground" )) X { X pixel = get_pixel( pres_resource->value ); X XtSetArg( scroll_args[num_scroll_args], XtNforeground, X pixel ); X num_scroll_args++; X goto next; X } X X if( !strcmp( pres_resource->name, "scrollfont" )) X { X font = XLoadQueryFont( XtDisplay( top_level), X pres_resource->value ); X XtSetArg( scroll_args[num_scroll_args], XtNfont, X font); X num_scroll_args++; X XtSetArg( label2_args[num_label2_args], XtNfont, X font); X num_label2_args++; X goto next; X } X X X if( !strcmp( pres_resource->name, "borderwidth" )) X { X XtSetArg( vpane_args[num_vpane_args], XtNborderWidth, X atoi( pres_resource->value )); X num_vpane_args++; X goto next; X } X X if( !strcmp( pres_resource->name, "bordercolor") ) X { X pixel = get_pixel( pres_resource->value ); X XtSetArg( vpane_args[num_vpane_args], XtNborderColor, X pixel) ; X num_vpane_args++; X goto next; X } X X if( !strcmp( pres_resource->name, "columns")) X { X column_label = scrollspace_label; X strcpy( column_label, " " ); X column_label += 2; X X column = 0; X temp = pres_resource->value; X X pres_grouped_arg = X (struct _grouped_arg *)malloc( X sizeof( struct _grouped_arg)); X X (*pres_cmd_arg)->grouped_arg = X pres_grouped_arg; X X while( *temp != '\0') X { X pres_grouped_arg = X (struct _grouped_arg *)malloc( X sizeof( struct _grouped_arg)); X X if( column == 0) X (*pres_cmd_arg)->grouped_arg = X pres_grouped_arg; X X else X prev_grouped_arg->next = X pres_grouped_arg; X X /* skip leading spaces */ X while ( *temp == ' ') X temp++; X X label_ptr = temp; X X /* find length of label */ X while( *temp != ':' && X *temp != ' ') X temp++; X X label_length = temp-label_ptr; X X strncpy( string, label_ptr, label_length); X *(string + label_length ) = '\0'; X X (pres_grouped_arg)->name_quark = XrmStringToQuark(string) ; X X /* skip trailing spaces */ X while( *temp == ' ' ) X temp++; X X /* check for syntax error X if( *temp != ':' ); /* error */ X X temp++; X X /* skip leading spaces */ X while( *temp == ' ' ) X temp++; X X number = temp; X X while( *temp != ' ' && X *temp != '\0' ) X temp++; X X while( *temp == ' ' ) X temp++; X X X number_length = temp - number; X X strncpy( string, number, number_length ); X X spreadsheet->column_width[column] = atoi( string ); X if( max_column_width < X spreadsheet->column_width[column]) X max_column_width = spreadsheet-> X column_width[column]; X if( column == 0) X pres_grouped_arg->value = X spreadsheet->scroll_string; X else X pres_grouped_arg->value = X prev_grouped_arg->value + X spreadsheet->column_width[column-1] + 2; X X spreadsheet->scrolltext_width += spreadsheet->column_width[column]; X X if( ((long)label_length) > spreadsheet->column_width[column]) X label_length = spreadsheet->column_width[column]; X X leading_spaces = spreadsheet->column_width[column]/2 - X label_length/2; X X strncpy( column_label, space_string, X leading_spaces); X X column_label += leading_spaces; X X X X X X strncpy( column_label, label_ptr, label_length ); X X *(column_label + label_length + 1) = '\0'; X X X trailing_spaces = spreadsheet->column_width[column] - X leading_spaces - label_length + 2; X X spreadsheet->scrolltext_width += 2 ; X X column_label += label_length; X X strncpy( column_label, X space_string, trailing_spaces ); X X column_label += trailing_spaces; X X column++; X X prev_grouped_arg = pres_grouped_arg; X } X X pres_grouped_arg->next = NULL; X X *(column_label ) = '\0'; X X spreadsheet->number_of_columns = column; X (*pres_cmd_arg)->num_columns = column; X X (*pres_cmd_arg)->scrolltext_width = spreadsheet-> X scrolltext_width; X X XtSetArg(label2_args[num_label2_args], X XtNlabel, scrollspace_label ); X num_label2_args++; X X if (font == NULL ) X { X fprintf( stderr, "In shell %s scrolltext %s:%s. No such font. Using internal default\n"); X font = XLoadQueryFont( XtDisplay(top_level), X "fixed" ); X } X X XtSetArg(scroll_args[num_scroll_args], X XtNwidth, X XTextWidth(font,scrollspace_label, X strlen( scrollspace_label )) ); X num_scroll_args++; X X X goto next; X } X X if( !strcmp( pres_resource->name, "horizdistance")) X { X XtSetArg(vpane_args[num_vpane_args], X XtNhorizDistance, X atoi(pres_resource->value)); X num_vpane_args++; X goto next; X } X X if( !strcmp( pres_resource->name, "vertdistance")) X { X XtSetArg(vpane_args[num_vpane_args], X XtNvertDistance, X atoi(pres_resource->value)); X num_vpane_args++; X goto next; X } X X if( !strcmp( pres_resource->name, "help")) X { X help_msg = pres_resource->value; X goto next; X } X Xnext: X pres_resource = pres_resource->next; X X } X X XtSetArg( vpane_args[num_vpane_args], XtNfromVert, X prev_widget); X num_vpane_args++; X X XtSetArg( vpane_args[num_vpane_args], XtNgripIndent, -30 ); X num_vpane_args++; X vpane = XtCreateManagedWidget("", vPanedWidgetClass, X outer_form, vpane_args, num_vpane_args ); X X XtSetArg(form_args[num_form_args], XtNdefaultDistance, 0 ); X num_form_args++; X form = XtCreateManagedWidget("", formWidgetClass, X vpane, form_args, num_form_args ); X X XtSetArg( label_args[num_label_args], XtNborderWidth, 0); X num_label_args++; X X label = XtCreateManagedWidget("", labelWidgetClass, X form, label_args, num_label_args ); X X XtSetArg(text_args[num_text_args], XtNfromHoriz, label ); X num_text_args++; X *(spreadsheet->input_string) = '\0'; X XtSetArg(text_args[num_text_args], XtNstring, X spreadsheet->input_string); X num_text_args++; X XtSetArg(text_args[num_text_args], XtNeditType, XttextEdit); X num_text_args++; X XtSetArg(text_args[num_text_args], XtNtextOptions, editable ); X num_text_args++; X XtSetArg(text_args[num_text_args], XtNlength, max_column_width); X num_text_args++; X XtSetArg(text_args[num_text_args], XtNwidth, X max_column_width * (font->max_bounds).width ); X num_text_args++; X XtSetArg(text_args[num_text_args], XtNfont, font); X num_text_args++; X spreadsheet->input_text = XtCreateManagedWidget("", X asciiStringWidgetClass, X form, text_args, num_text_args ); X enter_hash_help( spreadsheet->input_text, help_msg); X (*pres_cmd_arg)->input_text_widget = spreadsheet->input_text; X XtOverrideTranslations( spreadsheet->input_text, input_text_translations); X X XtOverrideTranslations( spreadsheet->input_text, X spread_input_translations); X XtSetArg(label2_args[num_label2_args], XtNjustify, X XtJustifyLeft); X num_label2_args++; X label2 = XtCreateManagedWidget("", labelWidgetClass, X vpane, label2_args, num_label2_args ); X X XtSetArg( scroll_args[num_scroll_args], XtNeditType, X XttextEdit ); X num_scroll_args++; X XtSetArg( scroll_args[num_scroll_args], XtNtextOptions, X scrollVertical|editable); X num_scroll_args++; X *(spreadsheet->scroll_string) = '\0'; X XtSetArg( scroll_args[num_scroll_args], XtNstring, X spreadsheet->scroll_string); X num_scroll_args++; X (*pres_cmd_arg)->scroll_string = spreadsheet->scroll_string; X X XtSetArg( scroll_args[num_scroll_args], XtNlength, X 1000); X num_scroll_args++; X spreadsheet->scroll_text = XtCreateManagedWidget("", asciiStringWidgetClass, X vpane, scroll_args, num_scroll_args ); X (*pres_cmd_arg)->text_widget = spreadsheet->scroll_text; X X XtOverrideTranslations( spreadsheet->scroll_text, X scroll_text_translations ); X X spreadsheet->cursor_position = 0; X spreadsheet->pres_column = 0; X X enter_spreadsheet( spreadsheet, vpane); X X return(vpane); X} X Xvoid copy_to_scroll(w) XWidget w; X{ X Arg args[3]; X XtTextBlock text; X int replace_end; X int temp; X XtArgVal cursor; X void update_input_string(); X X struct _spreadsheet *spreadsheet, X *get_spreadsheet_info(); X X spreadsheet = get_spreadsheet_info(XtParent(XtParent(w))); X X temp = strlen( spreadsheet->input_string ); X if ( temp > spreadsheet->column_width[ X spreadsheet->pres_column] ) X temp = spreadsheet->column_width[spreadsheet-> X pres_column]; X XtSetArg( args[0], XtNinsertPosition, X &cursor); X XtGetValues(spreadsheet->scroll_text, args, 1); X spreadsheet->cursor_position = (int)cursor; X X while( temp<(spreadsheet->column_width[ X spreadsheet->pres_column] + 2) ) X { X *(spreadsheet->input_string + temp ) = ' '; X temp++; X } X X if ( spreadsheet->pres_column+1 >= X spreadsheet->number_of_columns) X *(spreadsheet->input_string + temp -1 ) = '\n'; X X text.firstPos = 0; X text.ptr = spreadsheet->input_string; X text.length = temp; X X replace_end = (spreadsheet->cursor_position + X temp )>strlen(spreadsheet->scroll_string)? X strlen(spreadsheet->scroll_string): X spreadsheet->cursor_position + temp; X X XtTextReplace ( spreadsheet->scroll_text, X spreadsheet->cursor_position, X replace_end, &text ); X X spreadsheet->cursor_position += spreadsheet-> X column_width[spreadsheet->pres_column] + 2; X X spreadsheet->pres_column += 1; X X if(spreadsheet->pres_column + 1> spreadsheet->number_of_columns) X spreadsheet->pres_column = 0; X XtSetArg( args[0], XtNinsertPosition, spreadsheet->cursor_position); X XtSetValues( spreadsheet->scroll_text, args, 1); X X update_input_string(spreadsheet); X X} X X Xvoid update_cursor_position(w, event, params, num_params) XWidget w; XXEvent *event; XString *params; XCardinal *num_params; X{ X Arg args[3]; X int temp; X void update_input_string(); X XtArgVal cursor; X X struct _spreadsheet *spreadsheet, X *get_spreadsheet_info(); X X spreadsheet = get_spreadsheet_info(XtParent(w)); X X XtSetArg( args[0], XtNinsertPosition, X &cursor); X XtGetValues(w, args, 1); X spreadsheet->cursor_position = (int)cursor; X if( **params == '1' ) X { X spreadsheet->cursor_position += X spreadsheet->column_width[spreadsheet->pres_column] + 2; X X if( spreadsheet->cursor_position > X strlen( spreadsheet->scroll_string )) X { X spreadsheet->cursor_position -= X spreadsheet->column_width[ X spreadsheet->pres_column] + 2; X return; X } X X spreadsheet->pres_column++; X X if ( spreadsheet->pres_column +1 > X spreadsheet->number_of_columns ) X spreadsheet->pres_column = 0; X X } X X if( **params == '2' ) X { X temp = spreadsheet->pres_column; X X spreadsheet->pres_column--; X X if ( spreadsheet->pres_column < 0 ) X spreadsheet->pres_column = X spreadsheet->number_of_columns - 1; X X spreadsheet->cursor_position -= X spreadsheet->column_width[spreadsheet->pres_column] X + 2; X X if( spreadsheet->cursor_position < 0) X { X spreadsheet->cursor_position += X spreadsheet->column_width[ X spreadsheet->pres_column] + 2; X spreadsheet->pres_column = temp; X return; X } X X } X X if( **params == '3' ) X { X spreadsheet->cursor_position += X spreadsheet->scrolltext_width; X X if( spreadsheet->cursor_position > X (long)(strlen(spreadsheet->scroll_string))) X { X spreadsheet->cursor_position -= X spreadsheet->scrolltext_width; X return; X } X X } X X if( **params == '4' ) X { X spreadsheet->cursor_position -= X spreadsheet->scrolltext_width; X X if( spreadsheet->cursor_position < 0 ) X { X spreadsheet->cursor_position += X spreadsheet->scrolltext_width; X return; X } X } X X XtSetArg( args[0], XtNinsertPosition, X spreadsheet->cursor_position ); X X X XtSetValues( spreadsheet->scroll_text, args, 1 ); X X update_input_string(spreadsheet); X} X Xvoid update_input_string(spreadsheet) Xstruct _spreadsheet *spreadsheet; X{ X char *temp; X XtTextBlock text; X Arg args[2]; X char string[50]; X int length ; X X X temp = (char *)((long)(spreadsheet->scroll_string) + X spreadsheet->cursor_position); X X X while( *( temp ) != ' ' X && *( temp ) != '\0') X temp ++; X X /* strncpy( string, scroll_string+cursor_position X , temp-cursor_position); X /* *( string + temp-cursor_position ) = '\0'; X*/ X X text.length = (long)temp - spreadsheet-> X cursor_position - X (long)spreadsheet->scroll_string; X text.ptr = (char *)((long)spreadsheet->scroll_string + X spreadsheet->cursor_position); X text.firstPos = 0; X temp = spreadsheet->input_string; X while( *(temp) != '\0') X temp++; X X XtTextReplace( spreadsheet->input_text, 0, (long)temp - X (long)spreadsheet->input_string , X &text ); X XtSetArg( args[0], XtNinsertPosition, 0); X XtSetArg( args[1], XtNlength, spreadsheet->column_width[ X spreadsheet->pres_column] ); X XtSetValues( spreadsheet->input_text, args, 1); X X} X Xenter_spreadsheet( spreadsheet, widget_ptr ) Xstruct _spreadsheet *spreadsheet; XWidget widget_ptr; X{ X static int i= 0; X int key; X X if( i == 0 ) X { X for ( i == 0 ; i<MAX_NUM_SPREADSHEETS ; i++ ) X { X spreadsheet_info[i].widget_ptr = NULL; X } X } X X key = ((long) widget_ptr)%MAX_NUM_SPREADSHEETS; X X while( spreadsheet_info[key].widget_ptr != NULL) X key++; X X spreadsheet_info[key].widget_ptr = widget_ptr; X spreadsheet_info[key].spreadsheet = spreadsheet; X X return; X} X X X Xstruct _spreadsheet *get_spreadsheet_info(w) XWidget w; X{ X X int key; X X key = ((long)w)%MAX_NUM_SPREADSHEETS; X X while(w != spreadsheet_info[key].widget_ptr) X key++; X X return(spreadsheet_info[key].spreadsheet ); X X} X/* Xvoid check_length(w, event, params, num_params) X Widget w; X XEvent *event; X String *params; X Cardinal *num_params; X{ X XKeyEvent *keyevent; X keyevent = (XKeyEvent *)event; X keyevent->keycode = XKeysymToKeycode(0xFFB1); X} X*/ END_OF_FILE if test 20931 -ne `wc -c <'spreadsheet.c'`; then echo shar: \"'spreadsheet.c'\" unpacked with wrong size! fi # end of 'spreadsheet.c' fi echo shar: End of shell archive. exit 0