rsalz@uunet.uu.net (Rich Salz) (09/20/89)
Submitted-by: Brian Renaud <huron.ann-arbor.mi.us!bdr> Posting-number: Volume 20, Issue 18 Archive-name: metrics/part11 ---- Cut Here and unpack ---- #!/bin/sh # this is part 11 of a multipart archive # do not concatenate these parts, unpack them in order with /bin/sh # file src/testfiles/test2.y continued # CurArch=11 if test ! -r s2_seq_.tmp then echo "Please unpack part 1 first!" exit 1; fi ( read Scheck if test "$Scheck" != $CurArch then echo "Please unpack part $Scheck next!" exit 1; else exit 0; fi ) < s2_seq_.tmp || exit 1 echo "x - Continuing file src/testfiles/test2.y" sed 's/^X//' << 'SHAR_EOF' >> src/testfiles/test2.y X%token DECLARE CAST INTO AS HELP EXPLAIN X%token FUNCTION RETURNING POINTER TO ARRAY OF X%token <dynstr> NAME NUMBER STRUCTUNION UNSIGNED LONG SHORT X%token <dynstr> INT CHAR FLOAT DOUBLE X%type <dynstr> mod_list tname type modifier X%type <dynstr> cdecl cdecl1 cdims adims c_type X%type <halves> adecl X X%start prog X X%% Xprog : /* empty */ X | prog stat X ; X Xstat : HELP '\n' X { X help(); X } X | DECLARE NAME AS adecl '\n' X { X printf("%s %s%s%s",savedtype,$4.left,$2,$4.right); X#ifdef MKPROGRAM X if (prev == 'f') X printf("\n{\n}\n"); X else X printf(";\n"); X#else X printf("\n"); X#endif X free($4.left); X free($4.right); X free($2); X } X | CAST NAME INTO adecl '\n' X { X if (prev == 'f') X unsupp("Cast into function"); X else if (prev=='A' || prev=='a') X unsupp("Cast into array"); X printf("(%s",savedtype); X if (strlen($4.left)+strlen($4.right)) X printf(" %s%s",$4.left,$4.right); X printf(")%s\n",$2); X free($4.left); X free($4.right); X free($2); X } X | EXPLAIN type cdecl '\n' X { printf("declare %s as %s%s\n",savedname,$3,$2); } X | '\n' X | error '\n' X { X yyerrok; X } X ; X Xcdecl : cdecl1 X | '*' cdecl X { $$ = cat($2,ds("pointer to "),NULL); } X ; X Xcdecl1 : cdecl1 '(' ')' X { $$ = cat($1,ds("function returning "),NULL); } X | cdecl1 cdims X { $$ = cat($1,ds("array "),$2); } X | '(' cdecl ')' X { $$ = $2; } X | NAME X { X savename($1); X $$ = ds(""); X } X ; X Xcdims : '[' ']' X { $$ = ds("of "); } X | '[' NUMBER ']' X { $$ = cat($2,ds(" of "),NULL); } X ; X Xadecl : FUNCTION RETURNING adecl X { X if (prev == 'f') X unsupp("Function returning function"); X else if (prev=='A' || prev=='a') X unsupp("Function returning array"); X $$.left = $3.left; X $$.right = cat(ds("()"),$3.right,NULL); X prev = 'f'; X } X | FUNCTION '(' NAME ')' RETURNING adecl X { X if (prev == 'f') X unsupp("Function returning function"); X else if (prev=='A' || prev=='a') X unsupp("Function returning array"); X $$.left = $6.left; X $$.right = cat(ds("("),$3,ds(")")); X $$.right = cat($$.right,$6.right,NULL); X prev = 'f'; X } X | ARRAY adims OF adecl X { X if (prev == 'f') X unsupp("Array of function"); X else if (prev == 'a') X unsupp("Inner array of unspecified size"); X if (arbdims) X prev = 'a'; X else X prev = 'A'; X $$.left = $4.left; X $$.right = cat($2,$4.right,NULL); X } X | POINTER TO adecl X { X if (prev == 'a') X unsupp("Pointer to array of unspecified dimension"); X if (prev=='a' || prev=='A' || prev=='f') { X $$.left = cat($3.left,ds("(*"),NULL); X $$.right = cat(ds(")"),$3.right,NULL); X } else { X $$.left = cat($3.left,ds("*"),NULL); X $$.right = $3.right; X } X prev = 'p'; X } X | type X { X savetype($1); X $$.left = ds(""); X $$.right = ds(""); X prev = 't'; X } X ; X Xadims : /* empty */ X { X arbdims = 1; X $$ = ds("[]"); X } X | NUMBER X { X arbdims = 0; X $$ = cat(ds("["),$1,ds("]")); X } X ; X Xtype : tinit c_type X { mbcheck(); $$ = $2; } X ; X Xtinit : /* empty */ X { modbits = 0; } X ; X Xc_type : mod_list X { $$ = $1; } X | tname X { $$ = $1; } X | mod_list tname X { $$ = cat($1,ds(" "),$2); } X | STRUCTUNION NAME X { $$ = cat($1,ds(" "),$2); } X ; X Xtname : INT X { modbits |= MB_INT; $$ = $1; } X | CHAR X { modbits |= MB_CHAR; $$ = $1; } X | FLOAT X { modbits |= MB_FLOAT; $$ = $1; } X | DOUBLE X { modbits |= MB_DOUBLE; $$ = $1; } X ; X Xmod_list: modifier X { $$ = $1; } X | mod_list modifier X { $$ = cat($1,ds(" "),$2); } X ; X Xmodifier: UNSIGNED X { modbits |= MB_UNSIGNED; $$ = $1; } X | LONG X { modbits |= MB_LONG; $$ = $1; } X | SHORT X { modbits |= MB_SHORT; $$ = $1; } X ; X%% X#include "cdlex.c" X X#define LORS (MB_LONG|MB_SHORT) X#define UORL (MB_UNSIGNED|MB_LONG) X#define UORS (MB_UNSIGNED|MB_SHORT) X#define CORL (MB_CHAR|MB_LONG) X#define CORS (MB_CHAR|MB_SHORT) X#define CORU (MB_CHAR|MB_UNSIGNED) X Xmbcheck() X{ X if ((modbits&LORS) == LORS) X unsupp("conflicting 'short' and 'long'"); X if ((modbits&UORL) == UORL) X unport("unsigned with long"); X if ((modbits&UORS) == UORS) X unport("unsigned with short"); X if ((modbits&CORL) == CORL) X unsupp("long char"); X if ((modbits&CORS) == CORS) X unsupp("short char"); X if ((modbits&CORU) == CORU) X unport("unsigned char"); X} X Xsavetype(s) Xchar *s; X{ X savedtype = s; X} X Xsavename(s) Xchar *s; X{ X savedname = s; X} SHAR_EOF echo "File src/testfiles/test2.y is complete" chmod 0644 src/testfiles/test2.y || echo "restore of src/testfiles/test2.y fails" echo "x - extracting src/testfiles/test3.c (Text)" sed 's/^X//' << 'SHAR_EOF' > src/testfiles/test3.c X/* build a new stat data file based on data dictionary entries */ X X#include <stdio.h> X Xstruct fdesc /* description of field */ X{ X char *fd_name; /* name of field */ X int fd_fldno; /* field number in source file */ X struct fdesc *fd_next; /* next entry */ X}; X#define FDNULL ((struct fdesc *) 0) Xstruct fdesc *newfd(); X Xtypedef char Bool; X#define True 1 X#define False 0 X X#define CNULL ((char *) 0) X#define FNULL ((FILE *) 0) X XBool argcheck(); Xchar *buildcmd(); Xvoid data_filter(); Xint build_outlist(); XBool loaddd(); Xchar *Malloc(); X Xchar *Cmdname; Xstatic char *def_file = ".datadict"; /* default data dict name */ Xstatic struct fdesc *dd_current; /* used by firstdd, nextdd */ X Xint Xmain(argc, argv) X int argc; X char *argv[]; X{ X struct fdesc *fl_base = FDNULL, *curr_fl; /* fields in cmd line */ X struct fdesc *dd_base = FDNULL, *curr_dd; /* fields from dict */ X char *ddname = CNULL; X int fld_count = 0; X Bool exclude = False; X extern char * Cmdname; X X Cmdname = argv[0]; X if ( !argcheck( argc, argv, &fl_base, &ddname, &exclude ) ) X exit(1); X if ( ! loaddd( &dd_base, ddname ) ) X exit(1); X fld_count = build_outlist( &fl_base, dd_base, ddname, exclude ); X data_filter( fl_base, fld_count ); X exit(0); X} X X XBool Xargcheck( argc, argv, p_fl_base, p_ddname, p_exclude ) X int argc; X char *argv[]; X struct fdesc **p_fl_base; X char **p_ddname; X char *p_exclude; X{ X int idx; X char Usage[256]; X Bool gotdd = False; /* data dictionary specified on cmd line */ X Bool result = True; X struct fdesc *curr_fl; X extern char *Cmdname; X X sprintf( Usage, X "Usage: %s -x -f <data-dictionary> <field> [<field>]\n", X Cmdname); X if ( argc <= 1 ) X { X fprintf(stderr, Usage); X result = False; X } X X for ( idx = 1; idx < argc && result; idx++) X { X if ( *argv[idx] == '-' ) X { X switch ( argv[idx][1] ) X { X case 'f': /* next arg is data dictionary*/ X if ( idx == argc - 1 ) /* -f is last argument */ X { X fprintf(stderr, Usage ); X result = False; X } X else if ( gotdd ) /* already have a -f */ X { X fprintf(stderr, Usage); X result = False; X } X else X { X gotdd = True; X *p_ddname = argv[ ++idx ]; X } X break; X case 'x': /* exclude named fields */ X *p_exclude = True; X break; X default: /* unkown flag */ X fprintf(stderr, Usage); X result = False; X break; X } X } X else /* not a flag, must be a field name */ X { X if (*p_fl_base == FDNULL ) X curr_fl = newfd(p_fl_base, argv[idx], 0) ; X else X curr_fl = newfd( &(curr_fl->fd_next), X argv[idx],0); X } X } X return result; X} X X X XBool Xloaddd( p_dd_base, ddname ) X struct fdesc **p_dd_base; X char *ddname; X{ X Bool result = True; X struct fdesc *curr_dd; X FILE *ddfp; X char namebuf[80]; X int fieldno; X extern char *Cmdname; X extern char *def_file; X X if ( ddname == CNULL ) X ddname = def_file; X X if ( (ddfp = fopen( ddname, "r" )) == FNULL ) X { X fprintf(stderr, X "%s: unable to open data dictionary file\n", X Cmdname); X perror( ddname ); X result = False; X } X else X /* load up the data dictionary list */ X while (fscanf(ddfp, "%s %d\n", namebuf, &fieldno ) == 2) X { X if ( *p_dd_base == FDNULL ) X curr_dd = newfd( p_dd_base, X namebuf, fieldno ); X else X curr_dd = newfd( &(curr_dd->fd_next), X namebuf, fieldno); X if ( curr_dd->fd_fldno < 1 ) X { X fprintf(stderr, X "%s: field \"%s\" has an illegal field number (%d) in %s\n", X Cmdname, curr_dd->fd_name, X curr_dd->fd_fldno, ddname ); X result = False; X break; X } X } X return result; X} X XBool Xfinddd( p_ddrec, dd_base, searchstr ) X struct fdesc **p_ddrec; X struct fdesc *dd_base; X char *searchstr; X{ X struct fdesc *curr_dd; SHAR_EOF echo "End of part 11" echo "File src/testfiles/test3.c is continued in part 12" echo "12" > s2_seq_.tmp exit 0 -- Please send comp.sources.unix-related mail to rsalz@uunet.uu.net. Use a domain-based address or give alternate paths, or you may lose out.