vixie@wrl.dec.com (Paul Vixie) (05/03/90)
Submitted-by: vixie@wrl.dec.com (Paul Vixie) Posting-number: Volume 7, Issue 17 Archive-name: awl/part03 #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh <file", e.g.. If this archive is complete, you # will see the following message at the end: # "End of archive 3 (of 17)." # Contents: AwlP.h awl.lex dasm.c examples/awlculator.awl # examples/sample.awl resw_gp.c strftime.c # Wrapped by vixie@jove.pa.dec.com on Mon Apr 30 01:25:20 1990 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f 'AwlP.h' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'AwlP.h'\" else echo shar: Extracting \"'AwlP.h'\" \(7711 characters\) sed "s/^X//" >'AwlP.h' <<'END_OF_FILE' X#ifndef _AwlP_h X#define _AwlP_h X X/* $Header: /usr/src/local/awl/RCS/AwlP.h,v 2.3 90/04/19 20:04:05 jkh Exp $ */ X X/* X * X * Copyright 1989, 1990 X * Jordan K. Hubbard X * X * PCS Computer Systeme, GmbH. X * Munich, West Germany X * X * X * This file is part of AWL. X * X * AWL is free software; you can redistribute it and/or modify X * it under the terms of the GNU General Public License as published by X * the Free Software Foundation; either version 1, or (at your option) X * any later version. X * X * AWL is distributed in the hope that it will be useful, X * but WITHOUT ANY WARRANTY; without even the implied warranty of X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X * GNU General Public License for more details. X * X * You should have received a copy of the GNU General Public License X * along with AWL; see the file COPYING. If not, write to X * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. X * X * X */ X X/* X * This file contains the Awl Widget private declarations and data. X * X * $Log: AwlP.h,v $ X * Revision 2.3 90/04/19 20:04:05 jkh X * Alpha checkin. X * X * Revision 2.2 90/03/30 22:01:17 jkh X * Added alu_table_size X * X * Revision 2.1 90/03/30 01:06:51 jkh X * Added forward ref for do_optional_jump(). X * X * Revision 2.0 90/03/26 01:42:07 jkh X * pre-beta check-in X * X */ X X#include <X11/IntrinsicP.h> X#include <X11/ShellP.h> X#include <X11/StringDefs.h> X#include <X11/Shell.h> X#include <sys/types.h> X#include <sys/stat.h> X#include <setjmp.h> X#include <stdio.h> X#include <ctype.h> X#include <math.h> X#include <signal.h> X#include <varargs.h> X#ifdef PCS X#include <values.h> X#endif X#include "regex.h" X X/* #include <X11/Awl.h> */ X#include "Awl.h" X X#include "macros.h" X#include "hash.h" X#include "ltypes.h" X#include "patchlevel.h" X typedef struct { X int nichts; X} AwlClassPart; X typedef struct _AwlClassRec { X CoreClassPart core_class; X CompositeClassPart composite_class; X ShellClassPart shell_class; X WMShellClassPart wm_shell_class; X VendorShellClassPart vendor_shell_class; X TopLevelShellClassPart top_level_shell_class; X AwlClassPart awl_class; X} AwlClassRec; X extern AwlClassRec awlClassRec; X typedef struct { X /* resources */ X struct { X Boolean debug; /* debug parser */ X Boolean lineinfo; /* keep line number information */ X Boolean nowarn; /* don't output warnings */ X Boolean showasm; /* show assembly as generated */ X Boolean trace; /* show insn trace */ X Boolean version; /* print version information */ X String cpp_args; /* arguments to "cpp" command */ X String cpp_command; /* command name for "cpp" */ X String file; /* filename to parse */ X String *argv; /* optional starting arg vector */ X String startfunc; /* function to execute on startup */ X AwlExternList externlist; /* application externals */ X } res; X /* private state */ X struct { X Table top; /* the global symbol table */ X jmp_buf bomb_out; /* where to jump to on error */ X CTable ctable; /* global color table (optional) */ X } sysinfo; X struct { X FILE *in, *out, *err; /* widget stdin/stdout/stderr */ X String sep; /* what's magic for newline */ X int radix; /* i/o radix */ X } io; X struct { X LTabEnt *ltab; /* the line number table */ X int ltabsize, ltabcurr; /* max size, last entry */ X Breakpoint bkpts; /* breakpoint list */ X } debuginfo; X struct { X Datum *text; /* the text segment */ X Value *stack; /* the value stack */ X int etext; /* the end of the "text" segment */ X int estack; /* the end of the value stack */ X } seginfo; X struct { X int sp; /* the stack pointer */ X int fp; /* the frame pointer */ X int pc; /* the program counter */ X int oldsp; /* the saved SP */ X int nparms; /* number of parms on stack */ X } segptrs; X struct { X int lastpc; /* current compilation position */ X int lastinsn; /* for optimization */ X Layout active; /* intermediate widget layout */ X Layout current; /* for layout declarations */ X } compile; X} AwlPart; X typedef struct _AwlRec { X CorePart core; X CompositePart composite; X ShellPart shell; X WMShellPart wm; X VendorShellPart vendor; X TopLevelShellPart topLevel; X AwlPart awl; X} AwlRec; X X/* system routines */ X#ifdef __GNUC__ X#define alloca __builtin_alloca X#else Import char *alloca(); X#endif Import char *XtMalloc(), *bcopy(); Import int abs(); Import void bzero(), exit(); X X/* mapping routines from various gperf parsers */ Import WidgetClass map_wname_to_wclass(); Import String map_wclass_to_wname(); Import long map_wclass_to_flags(); Import int map_resword_to_token(); Import String map_token_to_resword(); Import String map_rname(); X X/* utility routines */ Import void backslash_eliminate(), append_string(), list_free(); Import Layout new_wl(); Import Generic convert_external(); Import Resource new_res(); Import Breakpoint new_bkpt(); Import AllocObj new_aobj(); Import AllocObj add_alloc(), sub_alloc(), mult_alloc(), div_alloc(); Import int sappend_string(), atonum(), strcomp(), stricomp(), list_len(); Import String numtoa(), ftoa(), s_strsed(), strsed(), skip_whitespace(); Import String datum_string_value(), value_string_value(), string_multiply(); Import String list_to_string(); Import String *list_from_string(); Import String *list_from_alist(); Import String *list_dup(); Import String format_time(), expand_stat(); Import Value coerce(); Import Process p_popen(); Import int p_pclose(); X X/* parsing routines */ Import int yyerror(); Import void yywarn(); Import int yylex(), yyparse(); X X/* disassembly/code info routines */ Import int op_nargs(), named_type(); Import void disasm(); Import LTabEnt *ltab_for_pc(); Import String op_name(), alu_name(), reg_name(), type_name(), X class_name(), describe_symbol(); X X/* Symbol routines */ Import void symbol_add(); Import void symbol_remove(); Import void symbol_def_constant(); Import void symbol_def_variable(); Import void symbol_set_locals(); Import Symbol symbol_new(); Import Symbol symbol_add_function(); Import Symbol symbol_find(); Import Symbol symbol_alist_find(); Import Symbol symbol_def_function(); Import String symbol_printname(); Import WidgetClass lookup_client_wclass(); X X/* Widget creation and manipulation routines */ Import void wset_arg_by_value(), create_widget(); Import void layout_create(), layout_destroy(), layout_realize(); Import void layout_manage(), layout_unmanage(); Import void layout_map(), layout_unmap(); Import void layout_popup(), layout_popdown(); Import Widget (*wcreate_rtn())(); Import WidgetClass layout_wclass(); Import Widget layout_id(); X X/* Compiler/Evaluator main functions */ Import Value pop(), tos(), Eval(), do_load(), do_register_load(); Import void do_init(), do_emit(), do_alu(); Import void do_push(), do_store(); Import void do_discard(), do_optional_jump(), do_link(), do_rts(); Import void push(); X X/* Evaluator utilities */ Import Value *do_dot_lookup(), do_convert(), get_arg(); Import Resource do_res_lookup(); Import Symbol do_new_label(); Import void adjust(), do_free(); Import void exec_error(), exec_warn(), debug(); Import void do_callback_user(), do_timer_user(); Import void do_action_user(), do_signal_user(); Import void do_workproc_user(); Import int parseFile(); X X/* Interesting global variables */ Import Datum TrueDatum, FalseDatum; Import Datum PopDupValue, PopDupTarget, PopDupNone, PopDiscard; Import InsnTable opcode_table[], alu_opcodes[]; Import int opcode_table_size, alu_table_size; X X/* from yylex() */ Import char *yy_file; Import int yy_line; X X#endif /* _AwlP_h */ END_OF_FILE if test 7711 -ne `wc -c <'AwlP.h'`; then echo shar: \"'AwlP.h'\" unpacked with wrong size! fi # end of 'AwlP.h' fi if test -f 'awl.lex' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'awl.lex'\" else echo shar: Extracting \"'awl.lex'\" \(6140 characters\) sed "s/^X//" >'awl.lex' <<'END_OF_FILE' X%{ X#ifndef lint static char *rcsid = "$Header: /usr/src/local/awl/RCS/awl.lex,v 2.4 90/04/19 20:04:21 jkh Exp $"; X#endif X X/* X * X * Copyright 1989 X * Jordan K. Hubbard X * X * PCS Computer Systeme, GmbH. X * Munich, West Germany X * X * X * This file is part of AWL. X * X * AWL is free software; you can redistribute it and/or modify X * it under the terms of the GNU General Public License as published by X * the Free Software Foundation; either version 1, or (at your option) X * any later version. X * X * AWL is distributed in the hope that it will be useful, X * but WITHOUT ANY WARRANTY; without even the implied warranty of X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X * GNU General Public License for more details. X * X * You should have received a copy of the GNU General Public License X * along with AWL; see the file COPYING. If not, write to X * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. X * X * X */ X X/* X * Here's awl's main lexer. X * X * $Log: awl.lex,v $ X * Revision 2.4 90/04/19 20:04:21 jkh X * Alpha checkin. X * X * Revision 2.3 90/04/13 16:32:06 jkh X * Added kludge to differentiate case (and default:) labels X * and ordinary labels properly. X * X * Revision 2.2 90/03/29 18:27:58 jkh X * Fixed labels. Added 3 new operators. X * X * Revision 2.0 90/03/26 01:42:44 jkh X * pre-beta check-in X * X */ X X#include "AwlP.h" X#include "y.tab.h" X X/* X * The next two vars are for error messages. I know about yylineno X * but found out that flex doesn't support it, so I use my own X * counter. This way you can use flex or lex [BTW, Vern, yylineno X * *is* documented for SYSV lex] X */ XExport char *yy_file = NULL; XExport int yy_line; X Import Widget _currW; X X/* X * We need this cruft to deal with the non-portable way flex deals X * with EOF (non-portable == pathologically incompatable with lex). X */ X#ifdef FLEX_SCANNER XExport lexer_reset() X{ X Import int yy_init; X X yy_init = 1; X} X#else XExport lexer_reset() X{} X#endif X X%} decdigit [0-9] hexdigit [0-9A-Fa-f] octdigit [0-7] uniqueid \$\? id [a-zA-Z_$][a-zA-Z_$0-9]* white [ \t]+ any [^\n] dot \. float {decdigit}*{dot}{decdigit}* nl [\n] dq-string \"([^"]|\\["])*\" sq-string \'[^\'\n]*\' string {dq-string} hexnum 0[xX]{hexdigit}+ octnum 0{octdigit}+ number {decdigit}+ X X%% X X{nl} yy_line++; X{white} ; X X"==" return(EE); X"<=" return(LE); X">=" return(GE); X"!=" return(NE); X"!!" return(NUKE); X"||" return(LOR); X"&&" return(LAND); X"+=" return(PE); X"-=" return(ME); X"*=" return(TE); X"/=" return(DE); X"%=" return(RE); X"^=" return(XE); X"|=" return(OE); X"&=" return(AE); X"~=" return(CE); X"<<=" return(SLE); X">>=" return(SRE); X"++" return(PP); X"--" return(MM); X"<<" return(SL); X">>" return(SR); X".." return(RANGE); X"!!" return(NUKE); X"??" return(MBR); X"<>" return(COPY); X X"+" return(PLUS); X"-" return(MINUS); X"*" return(MULT); X"/" return(DIV); X"%" return(MOD); X"^" return(XOR); X"|" return(OR); X"&" return(AND); X"~" return(COMP); X"." return(DOT); X"?" return(QST); X":" return(COL); X";" return(';'); X"," return(COMMA); X"{" return('{'); X"}" return('}'); X"[" return(LBRK); X"]" return(RBRK); X"(" return('('); X")" return(')'); X"=" return(EQ); X"<" return(LT); X">" return(GT); X"!" return(NOT); X X^"#"{any}* { X String fp, fp2; X Import int abs(); X X /* X * A comment, line control statement or weird cpp op to be X * ignored. If it's a line control statement, change the X * internal line number and file name, otherwise punt it. X */ X if (isdigit((*(yytext + 2))) && (fp=index(yytext, '"'))) { X yy_line = atonum(_currW, yytext + 1, 10); X if (yy_file) { X XtFree(yy_file); /* free old */ X yy_file = NULL; X } X if (*(++fp) == '"') /* stdin */ X yy_file = XtNewString("<stdin>"); X else { X fp2 = index(fp, '"'); X if (!fp2) X yyerror("Bad line control: %s", yytext); X else { X yy_file = XtMalloc((abs(fp2 - fp)) + 1); X strncpy(yy_file, fp, abs(fp2 - fp)); X yy_file[abs(fp2 - fp)] = '\0'; X } X } X } X } X X{sq-string} { X if (*(yytext + 1) == '\\') { X char tmp[6]; X X strncpy(tmp, yytext + 1, 5); X tmp[5] = '\0'; X backslash_eliminate(tmp, NORMAL_ELIMINATE, 0); X yylval.bval = *tmp; X return CHAR; X } X else if (strlen(yytext + 1) > 2) { X yyerror("Bad char constant %s", yytext); X return(0); X } X else { X yylval.bval = *(yytext + 1); X return CHAR; X } X } X X{string} { X /* nuke the quotes */ X yylval.sval = XtMalloc(strlen(yytext) + 1); X strcpy(yylval.sval, yytext+1); X yylval.sval[strlen(yylval.sval) - 1] = '\0'; X backslash_eliminate(yylval.sval, NORMAL_ELIMINATE, 0); X return STRING; X } X X{uniqueid} { X static int unique_id = 0; X char foo[128]; X X sprintf(foo, "_uniq_%x_%x_id", _currW, unique_id++); X yylval.sval = XtNewString(foo); X return IDENTIFIER; X } X X{id} { X int token; X /* is it a keyword like if, else, for, ... ? */ X if (token = map_resword_to_token(yytext, T_KEYWORD)) X return token; X /* how about a predefined type or class? */ X else if (yylval.ival = map_resword_to_token(yytext, X T_TYPE | X T_CLASS)) X return INT; X else if ((yylval.cval = map_wname_to_wclass(yytext)) || X (yylval.cval = lookup_client_wclass(_currW, X yytext))) X return WIDGET_TYPE; X else { X yylval.sval = XtNewString(yytext); X return IDENTIFIER; X } X } X X{hexnum} { yylval.ival = atonum(_currW, yytext, 16); return INT; } X X{octnum} { yylval.ival = atonum(_currW, yytext, 8); return INT; } X X{number} { yylval.ival = atonum(_currW, yytext, 10); return INT; } X X{float} { yylval.fval = atof(yytext); return FLOAT; } X X{any} { yyerror("Invalid character '%c'", *yytext); } X%% END_OF_FILE if test 6140 -ne `wc -c <'awl.lex'`; then echo shar: \"'awl.lex'\" unpacked with wrong size! fi # end of 'awl.lex' fi if test -f 'dasm.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'dasm.c'\" else echo shar: Extracting \"'dasm.c'\" \(7436 characters\) sed "s/^X//" >'dasm.c' <<'END_OF_FILE' X#ifndef lint static char *rcsid = "$Header: /usr/src/local/awl/RCS/dasm.c,v 2.1 90/03/30 22:00:03 jkh Exp $"; X#endif X X/* X * X * Copyright 1989 X * Jordan K. Hubbard X * X * PCS Computer Systeme, GmbH. X * Munich, West Germany X * X * X * This file is part of AWL. X * X * AWL is free software; you can redistribute it and/or modify X * it under the terms of the GNU General Public License as published by X * the Free Software Foundation; either version 1, or (at your option) X * any later version. X * X * AWL is distributed in the hope that it will be useful, X * but WITHOUT ANY WARRANTY; without even the implied warranty of X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X * GNU General Public License for more details. X * X * You should have received a copy of the GNU General Public License X * along with AWL; see the file COPYING. If not, write to X * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. X * X */ X X/* X * Functions for printing and disassembling portions of the text X * segment. Also contains some general instruction info functions for X * eval.c. X * X * $Log: dasm.c,v $ X * Revision 2.1 90/03/30 22:00:03 jkh X * Shuffled some stuff into evalutils.c X * X * Revision 2.0 90/03/26 01:44:19 jkh X * pre-beta check-in X * X */ X X#include "AwlP.h" X#include "y.tab.h" X X/* X * Return the print name for an opcode. Since the opcode table is always X * sorted, we can bsearch it. X */ XExport String op_name(insn) int insn; X{ X register int i, top = 0, bottom = opcode_table_size; X char *name = NULL; X X while (top <= bottom && name == NULL) { X i = (top + bottom) / 2; X if (opcode_table[i].insn == insn) X name = opcode_table[i].name; X else if (opcode_table[i].insn < insn) X top = i + 1; X else X bottom = i - 1; X } X return(name); X} X X/* X * Return the print name for an ALU opcode. Since the table is declared X * in order of increasing precendence (as is the grammer), we can bsearch X * it. X */ XExport String alu_name(op) int op; X{ X register int i, top = 0, bottom = alu_table_size; X char *name = NULL; X X while (top <= bottom && name == NULL) { X i = (top + bottom) / 2; X if (alu_opcodes[i].insn == op) X name = alu_opcodes[i].name; X else if (alu_opcodes[i].insn < op) X top = i + 1; X else X bottom = i - 1; X } X if (name) X return(name); X else X return("???"); X} X X/* Return the print name for a register */ XExport String reg_name(op) int op; X{ X if (op == _PC) X return("$PC"); X else if (op == _SP) X return("$SP"); X else if (op == _FP) X return("$FP"); X else X return("$??"); X} X X/* Return the print name for a type. */ XExport Inline String type_name(typ) short typ; X{ X String name; X X if (is_register(typ)) X name = reg_name(typ); X else X name = map_token_to_resword(typ, T_TYPE | T_INTERN_TYPE); X if (!name) X name = "???"; X return(name); X} X XExport Inline String class_name(class) short class; X{ X String name; X X if ((name = map_token_to_resword(class, T_CLASS)) == NULL) X name = "???"; X return(name); X} X Local int show_labels(sym, data) Symbol sym; int *data; X{ X if (symbol_class(sym) == LABEL && symbol_int(sym) == *data) X fprintf(awl_err(symbol_root(sym)), "%s:\n", symbol_name(sym)); X return(TRUE); X} X X/* X * Find the line table entry for a given PC, if possible. X */ XExport LTabEnt *ltab_for_pc(aw, pc) AwlWidget aw; int pc; X{ X LTabEnt *ret = NULL; X X if (awl_ltab(aw)) { X register int i, top, bottom; X int line; X X bottom = awl_ltabcurr(aw); X top = line = 0; X X while (top <= bottom && ret == NULL) { X i = (top + bottom) / 2; X if (ltab_start(awl_ltab(aw)[i]) <= pc && X ltab_last(awl_ltab(aw)[i]) >= pc) X ret = awl_ltab(aw) + i; X else if (ltab_last(awl_ltab(aw)[i]) < pc) X top = i + 1; X else X bottom = i - 1; X } X } X return(ret); X} X X/* to make a couple of expressions more readable later */ X#define SFDS(xx) symbol_function(datum_symbol(xx)) X X/* X * Disassemble instructions from l to n X */ XExport void disasm(aw, s, e) AwlWidget aw; int s, e; X{ X int nargs, insn, i; X char *op; X X if (e > awl_etext(aw)) X e = awl_etext(aw); X else if (s == e) X e += 1; X while (s < e) { X /* print any labels set to this address */ X hash_traverse(awl_top(aw), show_labels, &s); X X fprintf(awl_err(aw), "%#08x: ", s); X if ((nargs = op_nargs(insn = datum_int(awl_text(aw)[s]))) >= 0) { X op = op_name(datum_int(awl_text(aw)[s++])); X fputs(op, awl_err(aw)); X for (i = strlen(op); i < 8; i++) X fputc(' ', awl_err(aw)); X if (nargs == 0) X fputc('\n', awl_err(aw)); X else if (nargs == 1) { X switch(insn) { X case ALU: X fprintf(awl_err(aw), "%s\n", X alu_name(datum_int(awl_text(aw)[s++]))); X break; X X case JUMP: X case JUMPZ: X fprintf(awl_err(aw), "%s\n", X symbol_name(datum_symbol(awl_text(aw)[s++]))); X break; X X case CALL: X if (symbol_type(datum_symbol(awl_text(aw)[s])) == X FUNC_LAYOUT) X fprintf(awl_err(aw), "WL:<%s> ", X symbol_name(datum_symbol(awl_text(aw)[s]))); X else X fprintf(awl_err(aw), "<%s> ", X symbol_name(datum_symbol(awl_text(aw)[s]))); X if (function_uaddr(SFDS(awl_text(aw)[s])) == X UNDEF_ADDR) { X fprintf(awl_err(aw), "[undef]\n"); X s++; X } X else { X fprintf(awl_err(aw), "[%#0x]\n", X function_addr(SFDS(awl_text(aw)[s]))); X s++; X } X break; X X case OPEN: X fprintf(awl_err(aw), "%s\n", X map_wclass_to_wname(datum_wclass(awl_text(aw)[s++]))); X break; X X case POP: X switch(datum_int(awl_text(aw)[s++])) { X case NODUP: X fprintf(awl_err(aw), "[normal store]\n"); X break; X X case DISCARD: X fprintf(awl_err(aw), "[discard]\n"); X break; X X case DUPVAL: X fprintf(awl_err(aw), "[store and dup value]\n"); X break; X X case DUPTARG: X fprintf(awl_err(aw), "[store and dup target]\n"); X break; X X default: X fprintf(awl_err(aw), "[?? bad pop ??]\n"); X break; X } X break; X X case RTS: X fprintf(awl_err(aw), "%s\n", X datum_int(awl_text(aw)[s++]) ? "[with value]" X : "[without value]"); X break; X X default: X fprintf(awl_err(aw), "???\n"); X break; X } X } X else if (nargs == 2) { /* PUSH */ X char *pstr; X int cnst = FALSE; X int type = datum_int(awl_text(aw)[s]); X Datum data = awl_text(aw)[s + 1]; X X if (type != 0) { X if (type < 0) { X cnst = TRUE; X type = -type; X } X if (type == STRING) X pstr = "\"%s\"\n"; X else X pstr = "%s\n"; X if (cnst) X fprintf(awl_err(aw), "<C:%s> ", type_name(type)); X else X fprintf(awl_err(aw), "<%s> ", type_name(type)); X if (type == CHAR) X fprintf(awl_err(aw), "\'%#0x\'\n", datum_char(data)); X else if (type == SYMBOL) X fprintf(awl_err(aw), "<%s>\n", X symbol_printname(datum_symbol(data))); X else X fprintf(awl_err(aw), pstr, X datum_string_value(aw, type, data)); X } X else X fprintf(awl_err(aw), "*ILLEGAL PUSH ARGS*\n"); X s += 2; X } X else X fprintf(awl_err(aw), "???\n"); X } X else { X fprintf(awl_err(aw), "???\n"); X s++; X } X } X} END_OF_FILE if test 7436 -ne `wc -c <'dasm.c'`; then echo shar: \"'dasm.c'\" unpacked with wrong size! fi # end of 'dasm.c' fi if test -f 'examples/awlculator.awl' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'examples/awlculator.awl'\" else echo shar: Extracting \"'examples/awlculator.awl'\" \(7204 characters\) sed "s/^X//" >'examples/awlculator.awl' <<'END_OF_FILE' X/* -*-Mode: C; -*- */ X X/* This is unfinished. The hex buttons don't work, don't have time to X * fix them before alpha release. Should be done soon (simple). X */ X X#include <xt.h> X#include <xaw.h> X global bc_connection = 0; X global Top, result = 0, numstr = "", newop = 1; global cbase = "d"; X global do_key(), do_wop(), she_bam(), do_base(), do_allclear(); X create_calc_layout() X{ X local calc, dw = (CALLBACK)do_wop; X X calc = Form bevel { X XgTranslations (TRANSLATION) "#augment X <Key>q: exit(0) X None<Key>0:do_key(0)\n None<Key>1:do_key(1)\n None<Key>2:do_key(2) X None<Key>3:do_key(3)\n None<Key>4:do_key(4)\n None<Key>5:do_key(5) X None<Key>6:do_key(6)\n None<Key>7:do_key(7)\n None<Key>8:do_key(8) X None<Key>9:do_key(9)\n None<Key>.:do_key(.) X Shift<Key>+:do_key(+)\n None<Key>-:do_key(-) X Shift<Key>*:do_key(*)\n None<Key>/:do_key(/) X None<Key>=:do_key(=)\n <Key>C:do_key(C)"; X XtNbackgroundPixmap (XtRBitmap) "gray"; X Pane screen { X XtNbackgroundPixmap (XtRBitmap) "gray"; X Label display_area { X XgLabel "0"; X XgTextJustify XtJustifyLeft; X XgWidth 145; X XgBorderWidth 4; X } X Form frame { X XtNbackgroundPixmap (XtRBitmap) "gray"; X XtNfromVert (WIDGET)screen.display_area; X Form numbers { X XtNbackgroundPixmap (XtRBitmap) "gray"; X Button seven { X XgLabel "7"; X XgCallback dw; X } X Button eight { X XgLabel "8"; X XtNfromHoriz (WIDGET)numbers.seven; X XgCallback dw; X } X Button nine { X XgLabel "9"; X XtNfromHoriz (WIDGET)numbers.eight; X XgCallback dw; X } X Button four { X XgLabel "4"; X XtNfromVert (WIDGET)numbers.seven; X XgCallback dw; X } X Button five { X XgLabel "5"; X XtNfromVert (WIDGET)numbers.eight; X XtNfromHoriz (WIDGET)numbers.four; X XgCallback dw; X } X Button six { X XgLabel "6"; X XtNfromVert (WIDGET)numbers.nine; X XtNfromHoriz (WIDGET)numbers.five; X XgCallback dw; X } X Button one { X XgLabel "1"; X XtNfromVert (WIDGET)numbers.four; X XgCallback dw; X } X Button two { X XgLabel "2"; X XtNfromVert (WIDGET)numbers.five; X XtNfromHoriz (WIDGET)numbers.one; X XgCallback dw; X } X Button three { X XgLabel "3"; X XtNfromVert (WIDGET)numbers.six; X XtNfromHoriz (WIDGET)numbers.two; X XgCallback dw; X } X Button zero { X XgLabel "0"; X XtNfromVert (WIDGET)numbers.one; X XgCallback dw; X } X Button dot { X XgLabel "."; X XtNfromVert (WIDGET)numbers.two; X XtNfromHoriz (WIDGET)numbers.zero; X XgCallback dw; X } X Button blank { X XgLabel " "; X XtNfromVert (WIDGET)numbers.three; X XtNfromHoriz (WIDGET)numbers.dot; X } X Button de { X XgLabel "d"; X XtNfromVert (WIDGET)numbers.zero; X XtNsensitive FALSE; X XgCallback dw; X } X Button ee { X XgLabel "e"; X XtNfromVert (WIDGET)numbers.dot; X XtNfromHoriz (WIDGET)numbers.de; X XtNsensitive FALSE; X XgCallback dw; X } X Button ef { X XgLabel "f"; X XtNfromVert (WIDGET)numbers.blank; X XtNfromHoriz (WIDGET)numbers.ee; X XtNsensitive FALSE; X XgCallback dw; X } X Button aa { X XgLabel "a"; X XtNfromVert (WIDGET)numbers.de; X XtNsensitive FALSE; X XgCallback dw; X } X Button be { X XgLabel "b"; X XtNfromVert (WIDGET)numbers.ee; X XtNfromHoriz (WIDGET)numbers.aa; X XtNsensitive FALSE; X XgCallback dw; X } X Button ce { X XgLabel "c"; X XtNfromVert (WIDGET)numbers.ef; X XtNfromHoriz (WIDGET)numbers.be; X XtNsensitive FALSE; X XgCallback dw; X } X } X Form operators { X XtNbackgroundPixmap (XtRBitmap) "gray"; X XtNfromHoriz (WIDGET)frame.numbers; X Button plus { X XgLabel "+"; X XgCallback dw; X } X Button minus { X XgLabel "-"; X XtNfromVert (WIDGET)operators.plus; X XgCallback dw; X } X Button divide { X XgLabel "/"; X XtNfromHoriz (WIDGET)operators.plus; X XgCallback dw; X } X Button multiply { X XgLabel "*"; X XtNfromVert (WIDGET)operators.divide; X XtNfromHoriz (WIDGET)operators.minus; X XgCallback dw; X } X Button equals { X XgLabel "="; X XtNfromVert (WIDGET)operators.minus; X XgCallback (CALLBACK) she_bam; X } X Button rbase { X XgLabel "d"; X XtNfromVert (WIDGET)operators.multiply; X XtNfromHoriz (WIDGET)operators.equals; X XgCallback (CALLBACK) do_base; X } X Button allclear { X XgLabel "C"; X XtNfromVert (WIDGET)operators.equals; X XgCallback (CALLBACK) do_allclear; X } X } X } X } X }; X return(calc); X} X do_wop(w, client, data) X{ X lets_frag_the_leutenant((STRING)w[XgLabel]); X} X do_key(w, key) X{ X switch(key) { X case "=": X she_bam(); X break; X X case "C": X do_allclear(); X break; X X default: X lets_frag_the_leutenant(key); X } X} X lets_frag_the_leutenant(str) X{ X print(str); X X if (str ?? "0123456789.") { X if (newop) { X newop = FALSE; X numstr = str; X } X else X numstr += str; X } X else X newop = TRUE; X Top.bevel.screen.display_area[XgLabel] = numstr; X} X she_bam(w, client, data) X{ X println(); X result = get(STRING); X X if ("^syntax error" ?? result) X XBell(); X else { X numstr = ""; X Top.bevel.screen.display_area[XgLabel] = result; X } X} X do_base() X{ X if (cbase == "d") { X cbase = "o"; X println("ibase=8"); X println("obase=8"); X Top.bevel.screen.frame.numbers.eight[XtNsensitive] = FALSE; X Top.bevel.screen.frame.numbers.nine[XtNsensitive] = FALSE; X } else if (cbase == "o") { X cbase = "h"; X println("ibase=16"); X println("obase=16"); X Top.bevel.screen.frame.numbers.eight[XtNsensitive] = TRUE; X Top.bevel.screen.frame.numbers.nine[XtNsensitive] = TRUE; X Top.bevel.screen.frame.numbers.aa[XtNsensitive] = TRUE; X Top.bevel.screen.frame.numbers.be[XtNsensitive] = TRUE; X Top.bevel.screen.frame.numbers.ce[XtNsensitive] = TRUE; X Top.bevel.screen.frame.numbers.de[XtNsensitive] = TRUE; X Top.bevel.screen.frame.numbers.ee[XtNsensitive] = TRUE; X Top.bevel.screen.frame.numbers.ef[XtNsensitive] = TRUE; X } else { X cbase = "d"; X println("ibase=10"); X println("obase=10"); X Top.bevel.screen.frame.numbers.aa[XtNsensitive] = FALSE; X Top.bevel.screen.frame.numbers.be[XtNsensitive] = FALSE; X Top.bevel.screen.frame.numbers.ce[XtNsensitive] = FALSE; X Top.bevel.screen.frame.numbers.de[XtNsensitive] = FALSE; X Top.bevel.screen.frame.numbers.ee[XtNsensitive] = FALSE; X Top.bevel.screen.frame.numbers.ef[XtNsensitive] = FALSE; X } X X Top.bevel.screen.frame.operators.rbase[XgLabel] = cbase; X} X do_allclear() X{ X numstr = ""; X Top.bevel.screen.display_area[XgLabel] = "0"; X} X X/* Handle sudden death */ sudden_death() X{ X Top.bevel.screen.display_area[XgLabel] = "*CROAK*"; X XtSetSensitive(Top, FALSE); X} X X/* Your milage may differ */ X#define SIGCHLD 23 X#define SIGPIPE 13 main() X{ X signal(SIGCHLD, sudden_death); X signal(SIGPIPE, sudden_death); X bc_connection = open("bc", "+p"); X setbuf(bc_connection, NULL, NULL); X assign(bc_connection, stdin); X assign(bc_connection, stdout); X X /* create the top view */ X Top = Shell awlcalc { X XtNtitle "Awlculator"; X create_calc_layout(); X }; X XtCreateManaged(Top); X XtPopup(Top, XtGrabNone); X do_allclear(); X} END_OF_FILE if test 7204 -ne `wc -c <'examples/awlculator.awl'`; then echo shar: \"'examples/awlculator.awl'\" unpacked with wrong size! fi # end of 'examples/awlculator.awl' fi if test -f 'examples/sample.awl' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'examples/sample.awl'\" else echo shar: Extracting \"'examples/sample.awl'\" \(7830 characters\) sed "s/^X//" >'examples/sample.awl' <<'END_OF_FILE' X/* -*-Mode: C; -*- */ X X#include <xt.h> X X/* X * This is a sample layout borrowed from the widget layout X * package recently posted to comp.sources.x by Dwight Cooper. It served X * (albeit in a much converted form) as a target while I wrote my package. X * X * (Note: Out of fairness to Dwight, I must confess to having substantially X * changed some of the labels after reading "Chernobyl" by Frederik Pohl. -jh) X * X * This layout shows how you can obey a reasonable number of "standard" X * resource naming conventions, even though we're not C. Too bad there isn't X * a header file like "StringDefs.h" for every widget type, then X * we wouldn't have to do any grubbing around for the includes to make the X * "<wlib>.h." files.. Ah well. X */ X X/* Time in milliseconds between "emergency" flashes */ X#define FLASHTIME 600 X global do_melt(), do_quit(), spawn(), stop_flashing(); global Mainpanel, Quitpanel = 0; X create_panel() X{ X local retv; X X retv = Shell panel { X XgFont (XtRFont)"9x15"; X Pane pane_1 { X XgWidth 650; X XgHeight 350; X Label top { X XgLabel "Reactor Control Panel"; X XgCursor (XtRCursor)"pirate"; X XgForeground (XtRPixel)"Black"; X XgBackground (XtRPixel)"White"; X XgFont (XtRFontStruct)"helvb24"; X XgPaneMinHeight 30; X } X Form form_1 { X Form form_2 { X XgBorderWidth 0; X Button Start { X XgWidth 60; X XgCallback (CALLBACK)spawn; X } X Button Stop { X XgFormVertWidget (WIDGET)form_2.Start; X XgCallback (CALLBACK)stop_flashing; X XgWidth 60; X } X Button Melt { X XgFormVertWidget (WIDGET)form_2.Stop; X XgCallback (CALLBACK)do_melt; X XgWidth 60; X } X Button Quit { X XgFormVertWidget (WIDGET)form_2.Melt; X XgCallback (CALLBACK)do_quit; X XgWidth 60; X } X } X Form form_3 { X XgFormHorizWidget (WIDGET)form_1.form_2; X XgBorderWidth 0; X Button button_1 { X XgLabel " "; X XgForeground (XtRPixel)"white"; X XgBackground (XtRPixel)"black"; X } X Label label_1 { X XgLabel "Coolant leaking:"; X XgWidth 120; X XgFormHorizWidget (WIDGET)form_3.button_1; X XgTextJustify XtJustifyLeft; X XgBorderWidth 0; X } X AsciiText text_1 { X XgTextString "200 (decaliters)"; X XgFormHorizWidget (WIDGET)form_3.label_1; X XgWidth 200; X } X Button button_2 { X XgLabel " "; X XgFormVertWidget (WIDGET)form_3.button_1; X } X Label label_2 { X XgLabel "Proj. MTBF:"; X XgWidth 120; X XgFormVertDist 8; X XgFormHorizWidget (WIDGET)form_3.button_2; X XgFormVertWidget (WIDGET)form_3.label_1; X XgTextJustify XtJustifyLeft; X XgBorderWidth 0; X } X AsciiText text_2 { X XgTextString "10 minutes (approx)"; X XgFormHorizWidget (WIDGET)form_3.label_2; X XgFormVertWidget (WIDGET)form_3.text_1; X XgWidth 200; X } X Button button_3 { X XgLabel " "; X XgForeground (XtRPixel)"White"; X XgBackground (XtRPixel)"Black"; X XgFormVertWidget (WIDGET)form_3.button_2; X } X Label label_3 { X XgLabel "RADS (core)"; X XgWidth 120; X XgFormVertDist 8; X XgFormHorizWidget (WIDGET)form_3.button_3; X XgFormVertWidget (WIDGET)form_3.label_2; X XgTextJustify XtJustifyLeft; X XgBorderWidth 0; X } X AsciiText text_3 { X XgTextString "300"; X XgFormHorizWidget (WIDGET)form_3.label_3; X XgFormVertWidget (WIDGET)form_3.text_2; X XgWidth 200; X } X Button button_4 { X XgLabel " "; X XgFormVertWidget (WIDGET)form_3.button_3; X } X Label label_4 { X XgLabel "RADS (control room)"; X XgWidth 120; X XgFormVertDist 8; X XgFormHorizWidget (WIDGET)form_3.button_4; X XgFormVertWidget (WIDGET)form_3.label_3; X XgTextJustify XtJustifyLeft; X XgBorderWidth 0; X } X AsciiText text_4 { X XgTextString "(?)"; X XgFormHorizWidget (WIDGET)form_3.label_4; X XgFormVertWidget (WIDGET)form_3.text_3; X XgWidth 200; X } X } X } X Form form_4 { X Label mode_label_1 { X XgLabel "Abort On Meltdown"; X XgTextJustify XtJustifyLeft; X XgBorderWidth 0; X XgWidth 150; X } X Button mode_button_1 { X XgLabel "No"; X XgFormHorizWidget (WIDGET)form_4.mode_label_1; X } X Label mode_label_2 { X XgLabel "Mode"; X XgTextJustify XtJustifyLeft; X XgBorderWidth 0; X XgFormVertWidget (WIDGET)form_4.mode_label_1; X XgWidth 150; X } X Button mode_button_2 { X XgLabel "Perking"; X XgFormHorizWidget (WIDGET)form_4.mode_label_2; X XgFormVertWidget (WIDGET)form_4.mode_button_1; X } X Label mode_label_3 { X XgLabel "Employees on watch"; X XgTextJustify XtJustifyLeft; X XgBorderWidth 0; X XgFormVertWidget (WIDGET)form_4.mode_label_2; X XgWidth 150; X } X Button mode_button_3 { X XgLabel "2"; X XgFormHorizWidget (WIDGET)form_4.mode_label_3; X XgFormVertWidget (WIDGET)form_4.mode_button_2; X } X Label mode_label_4 { X XgLabel "Failsafe switch"; X XgTextJustify XtJustifyLeft; X XgBorderWidth 0; X XgFormVertWidget (WIDGET)form_4.mode_label_3; X XgWidth 150; X } X Button mode_button_4 { X XgLabel "(disabled)"; X XgFormHorizWidget (WIDGET)form_4.mode_label_4; X XgFormVertWidget (WIDGET)form_4.mode_button_3; X } X } X Form form_5 { X XgFormVertWidget (WIDGET)pane_1.form_4; X AsciiText status_text { X XgTextString "Reactor Controller Ready> "; X XgTextInsertPosition 2; X } X } X } X }; X return(retv); X} X popdown_popup() X{ X XtPopdown(Quitpanel); X Mainpanel.pane_1.form_1.form_2.Quit[XtNsensitive] = TRUE; X} X create_popup() X{ X local retv; X X retv = Shell "quit?" { X Form form_1 { X Label msg { X XgLabel "Do you really want to quit?"; X } X Button yes { X XgLabel " Yes "; X /* We'll exit with the widget value here, but who cares? */ X XgCallback (CALLBACK)exit; X XgFormVertWidget (WIDGET)form_1.msg; X } X Button no { X XgLabel " No "; X XgCallback (CALLBACK)popdown_popup; X XgFormVertWidget (WIDGET)form_1.msg; X XgFormHorizWidget (WIDGET)form_1.yes; X } X } X }; X return(retv); X} X do_quit() X{ X if (!Quitpanel) X Quitpanel = XtRealize(XtCreateManaged(create_popup())); X XtPopup(Quitpanel, XtGrabNone); X Mainpanel.pane_1.form_1.form_2.Quit[XtNsensitive] = FALSE; X} X spawn() { XtPopup(XtRealize(XtCreateManaged(create_panel())), XtGrabNone); } X meltdown(sym, id) X{ X /* X * Initialize the first time around to avoid wastefully allocating X * the same colors every time we flash. X */ X if (!melt) { X white = (XtRPixel)"White"; X black = (XtRPixel)"Black"; X } X melt++; X if (melt % 2) { X Mainpanel.pane_1.form_4.mode_button_2[XgLabel] = "EMERGENCY"; X Mainpanel.pane_1.top[XgForeground] = white; X Mainpanel.pane_1.top[XgBackground] = black; X } X else { X Mainpanel.pane_1.form_4.mode_button_2[XgLabel] = "CALL 911"; X Mainpanel.pane_1.top[XgForeground] = black; X Mainpanel.pane_1.top[XgBackground] = white; X } X timer = XtAddTimeOut(FLASHTIME, meltdown); X} X do_melt(w, client, data) X{ X melt = 0; X timer = XtAddTimeOut(FLASHTIME, meltdown); X} X stop_flashing(panel) X{ X if (timer != "timer") { X XtRemoveTimeOut(timer); X timer = 0; X Mainpanel.pane_1.form_4.mode_button_2[XgLabel] = "Ok.."; X } X else X Mainpanel.pane_1.form_4.mode_button_2[XgLabel] = "Not melting"; X} X main() X{ X Mainpanel = create_panel(); X XtPopup(XtCreateManaged(Mainpanel), XtGrabNone); X} END_OF_FILE if test 7830 -ne `wc -c <'examples/sample.awl'`; then echo shar: \"'examples/sample.awl'\" unpacked with wrong size! fi # end of 'examples/sample.awl' fi if test -f 'resw_gp.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'resw_gp.c'\" else echo shar: Extracting \"'resw_gp.c'\" \(6221 characters\) sed "s/^X//" >'resw_gp.c' <<'END_OF_FILE' X/* C code produced by gperf version 1.9.1 (K&R C version) */ X/* Command-line: gperf -t -p -o -g -G -N is_resword resw.gperf */ X X X#ifndef lint static char *rcsid = "$Header: /usr/src/local/awl/RCS/resw_gp.c,v 1.1 90/04/19 20:05:33 jkh Exp $"; X#endif X X/* X * X * Copyright 1989 X * Jordan K. Hubbard X * X * PCS Computer Systeme, GmbH. X * Munich, West Germany X * X * X * This file is part of AWL. X * X * AWL is free software; you can redistribute it and/or modify X * it under the terms of the GNU General Public License as published by X * the Free Software Foundation; either version 1, or (at your option) X * any later version. X * X * AWL is distributed in the hope that it will be useful, X * but WITHOUT ANY WARRANTY; without even the implied warranty of X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X * GNU General Public License for more details. X * X * You should have received a copy of the GNU General Public License X * along with AWL; see the file COPYING. If not, write to X * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. X * X * X */ X X/* X * This is the gperf hash table for all reserved words in awl. X * X * $Log: resw_gp.c,v $ X * Revision 1.1 90/04/19 20:05:33 jkh X * Initial revision X * X * Revision 2.3 90/04/13 16:33:45 jkh X * Changed naming convention for FUNC_ types. X * X * Revision 2.2 90/04/01 00:09:50 jkh X * Added FUNC_EXTERN type. X * X * Revision 2.1 90/03/29 18:28:53 jkh X * Added switch/case/default keywords. X * X * Revision 2.0 90/03/26 01:43:40 jkh X * pre-beta check-in X * X */ X X#include "AwlP.h" X#include "y.tab.h" X struct Reswords { char *name; int token; int type; }; X X#define MIN_WORD_LENGTH 2 X#define MAX_WORD_LENGTH 13 X#define MIN_HASH_VALUE 2 X#define MAX_HASH_VALUE 85 X/* X 50 keywords X 84 is the maximum key range X*/ X X#ifdef __GNUC__ inline X#endif static int hash (str, len) X register char *str; X register unsigned int len; X{ X static unsigned char hash_table[] = X { X 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, X 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, X 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, X 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, X 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, X 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, X 85, 85, 85, 85, 85, 0, 85, 15, 30, 50, X 0, 20, 85, 40, 85, 20, 40, 85, 40, 85, X 20, 85, 10, 10, 15, 85, 85, 0, 85, 5, X 85, 85, 85, 85, 85, 85, 85, 85, 45, 5, X 0, 0, 0, 41, 5, 10, 85, 0, 0, 85, X 0, 0, 85, 85, 0, 0, 0, 35, 85, 30, X 85, 85, 85, 85, 85, 85, 85, 85, X }; X return len + hash_table[str[len - 1]] + hash_table[str[0]]; X} X X static struct Reswords wordlist[] = X{ X {"",}, {"",}, X {"do", DO, T_KEYWORD}, X {"for", FOR, T_KEYWORD}, X {"else", ELSE, T_KEYWORD}, X {"local", LOCAL, T_KEYWORD}, X {"return", RETURN, T_KEYWORD}, X {"default", DEFAULT, T_KEYWORD}, X {"ANY", ANY, T_TYPE}, X {"case", CASE, T_KEYWORD}, X {"FUNC_UNDEF", FUNC_UNDEF, T_INTERN_TYPE}, X {"switch", SWITCH, T_KEYWORD}, X {"if", IF, T_KEYWORD}, X {"continue", CONTINUE, T_KEYWORD}, X {"",}, X {"FADDR", FADDR, T_TYPE}, X {"WCLASS", WCLASS, T_TYPE}, X {"",}, {"",}, X {"FUNC_USER", FUNC_USER, T_INTERN_TYPE}, X {"FLOAT", FLOAT, T_TYPE}, X {"WIDGET", WIDGET, T_TYPE}, X {"",}, X {"FILEDESC", FILEDESC, T_INTERN_TYPE}, X {"FILEPDESC", FILEPDESC, T_INTERN_TYPE}, X {"SADDR", SADDR, T_TYPE}, X {"FUNC_LAYOUT", FUNC_LAYOUT, T_INTERN_TYPE}, X {"",}, {"",}, X {"CHAR", CHAR, T_TYPE}, X {"CADDR", CADDR, T_TYPE}, X {"STATIC", STATIC, T_CLASS}, X {"",}, X {"FUNC_CALLBACK", FUNC_CALLBACK, T_INTERN_TYPE}, X {"DATA", DATA, T_CLASS}, X {"while", WHILE, T_KEYWORD}, X {"STRING", STRING, T_TYPE}, X {"",}, X {"CONSTANT", CONSTANT, T_CLASS}, X {"ALLOCATED", ALLOCATED, T_CLASS}, X {"until", UNTIL, T_KEYWORD}, X {"",}, {"",}, X {"CALLBACK", CALLBACK, T_TYPE}, X {"",}, X {"goto", GOTO, T_KEYWORD}, X {"PIXMAP", PIXMAP, T_TYPE}, X {"global", GLOBAL, T_KEYWORD}, X {"FUNCTION", FUNCTION, T_CLASS}, X {"",}, X {"break", BREAK, T_KEYWORD}, X {"FUNC_ACTION", FUNC_ACTION, T_INTERN_TYPE}, X {"FUNC_BUILTIN", FUNC_BUILTIN, T_INTERN_TYPE}, X {"FUNC_EXTERNAL", FUNC_EXTERN, T_INTERN_TYPE}, X {"",}, X {"IADDR", IADDR, T_TYPE}, X {"SYMBOL", SYMBOL, T_INTERN_TYPE}, X {"",}, X {"INT", INT, T_TYPE}, X {"LIST", LIST, T_TYPE}, X {"",}, X {"LAYOUT", LAYOUT, T_TYPE}, X {"",}, X {"INDIRECT", INDIRECT, T_CLASS}, X {"",}, X {"RANGE", RANGE, T_INTERN_TYPE}, X {"TRANSLATION", TRANSLATION, T_TYPE}, X {"",}, X {"RESOURCE", RESOURCE, T_INTERN_TYPE}, X {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, X {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, X {"LABEL", LABEL, T_CLASS}, X}; X X#ifdef __GNUC__ inline X#endif struct Reswords * is_resword (str, len) X register char *str; X register unsigned int len; X{ X if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) X { X register int key = hash (str, len); X X if (key <= MAX_HASH_VALUE && key >= MIN_HASH_VALUE) X { X register char *s = wordlist[key].name; X X if (*s == *str && !strcmp (str + 1, s + 1)) X return &wordlist[key]; X } X } X return 0; X} X X/* X * Look up a reserved word by name and token type. X */ XExport int map_resword_to_token(name, type) String name; short type; X{ X struct Reswords *rw; X X if ((rw = is_resword(name, strlen(name))) != NULL && rw->type & type) X return(rw->token); X else X return(0); X} X X/* X * Look up the name of a reserved word by token and type. X */ XExport String map_token_to_resword(token, type) register short token; register short type; X{ X register int i, limit = (sizeof(wordlist) / sizeof(struct Reswords)); X X for (i = 0; i < limit; i++) X if (wordlist[i].token == token && wordlist[i].type & type) X return(wordlist[i].name); X return((String)0); X} END_OF_FILE if test 6221 -ne `wc -c <'resw_gp.c'`; then echo shar: \"'resw_gp.c'\" unpacked with wrong size! fi # end of 'resw_gp.c' fi if test -f 'strftime.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'strftime.c'\" else echo shar: Extracting \"'strftime.c'\" \(6675 characters\) sed "s/^X//" >'strftime.c' <<'END_OF_FILE' X#ifndef lint static char *rcsid = "$Header: /usr1/src/local/awl/RCS/strftime.c,v 1.1 90/04/21 23:12:20 jkh Exp $"; X#endif X X/* Copyright (C) 1990 Free Software Foundation, Inc. X This file is part of the GNU C Library. X X The GNU C Library is free software; you can redistribute it and/or modify X it under the terms of the GNU General Public License as published by X the Free Software Foundation; either version 1, or (at your option) X any later version. X X The GNU C Library is distributed in the hope that it will be useful, X but WITHOUT ANY WARRANTY; without even the implied warranty of X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the X GNU General Public License for more details. X X You should have received a copy of the GNU General Public License X along with the GNU C Library; see the file COPYING. If not, write to X the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ X X/* X * Made some changes to remove inter-GNU dependencies that I don't have access X * to yet (when the GNU C library is released, I can go that route instead) X * and edited to conform to the overall awl style. Since this has to be X * included with AWL for now (and the whole thing's under the GPL anyway), I X * figured that it would be better to keep everything in sync. I've done the X * same with regex.[ch]. X * X * Jordan Hubbard X * X * $Log: strftime.c,v $ X * Revision 1.1 90/04/21 23:12:20 jkh X * Initial revision X * X * X */ X X#include "AwlP.h" X X/* These I had to add myself. Not very international, I'm afraid. -jkh */ Local String A_wkday[] = { X "Sun", "Mon", "Tue", "Wed","Thu", "Fri", "Sat", X}; X Local String F_wkday[] = { X "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", X "Saturday", X}; X Local String A_month[] = { X "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", X "Nov", "Dec", X}; X Local String F_month[] = { X "January", "February", "March","April", "May", "June", "July", X "August", "September", "October", "November", "December", X}; X Local String AP[] = { X "AM", "PM", X}; X X#define add(n, f) \ X do { \ X i += (n); \ X if (i >= maxsize) \ X return 0; \ X else if (p != NULL) { \ X f; \ X p += (n); \ X } \ X } while (0) X X#define cpy(n, s) add((n), memcpy((Generic) p, (Generic) (s), (n))) X#define fmt(n, args) add((n), if (sprintf args != (n)) return 0) X X/* X * Return the week in the year specified by TP, X * with weeks starting on STARTING_DAY. X */ Local unsigned int week(tp, starting_day) struct tm *tp; int starting_day; X{ X int wday, dl; X X wday = tp->tm_wday - starting_day; X if (wday < 0) X wday += 7; X X /* X * Set DL to the day in the year of the last day of the week previous X * to the one containing the day specified in TP. If DL is negative or X * zero, the day specified in TP is in the first week of the year. X * Otherwise, calculate the number of complete weeks before our week X * (DL / 7) and add any partial week at the start of the year (DL % 7). X */ X dl = tp->tm_yday - wday; X return dl <= 0 ? 0 : ((dl / 7) + ((dl % 7) == 0 ? 0 : 1)); X} X X/* X * Write information from TP into S according to the format X * string FORMAT, writing no more that MAXSIZE characters X * (including the terminating '\0') and returning number of X * characters written. If S is NULL, nothing will be written X * anywhere, so to determine how many characters would be X * written, use NULL for S and (int UINT_MAX for MAXSIZE. X */ int strftime(s, maxsize, format, tp) char *s; int maxsize; char *format; register struct tm *tp; X{ X char *a_wkday = A_wkday[tp->tm_wday]; X char *f_wkday = F_wkday[tp->tm_wday]; X char *a_month = A_month[tp->tm_mon]; X char *f_month = F_month[tp->tm_mon]; X int aw_len = strlen(a_wkday); X int am_len = strlen(a_month); X int wkday_len = strlen(f_wkday); X int month_len = strlen(f_month); X int hour12 = tp->tm_hour; X char *ampm = AP[hour12 > 12]; X int ap_len = strlen(ampm); X unsigned int y_week0 = week(tp, 0); X unsigned int y_week1 = week(tp, 1); X char *zone; X int zonelen; X register int i = 0; X register char *p = s; X register char *f; X X if (tp->tm_isdst < 0) { X zone = ""; X zonelen = 0; X } X else { X#ifdef SYSV /* I think tzname is SYSV only */ X zone = tzname[tp->tm_isdst]; X#else X zone = "BSD"; /* be cute in the face of failure */ X#endif X zonelen = strlen(zone); X } X X if (hour12 > 12) X hour12 -= 12; X else if (hour12 == 0) X hour12 = 12; X X for (f = format; *f != '\0'; ++f) { X char *subfmt; X X if (!isascii(*f)) { X /* Non-ASCII, may be a multibyte. (ho ho. Ahem. PUNT -jkh) */ X /* int len = mblen(f, strlen(f)); */ X int len = strlen(f); X X if (len > 0) { X cpy(len, f); X continue; X } X } X X if (*f != '%') { X add(1, *p = *f); X continue; X } X X ++f; X switch (*f) { X case '%': X add(1, *p = *f); X break; X case 'a': X cpy(aw_len, a_wkday); X break; X case 'A': X cpy(wkday_len, f_wkday); X break; X case 'b': X cpy(am_len, a_month); X break; X case 'B': X cpy(month_len, f_month); X break; X case 'c': X subfmt = "%A %B, %d. %Y, %X %Z"; X subformat:; X { X int len = strftime(p, maxsize - i, subfmt, tp); X add(len, ); X } X break; X case 'd': X fmt(2, (p, "%.2d", tp->tm_mday)); X break; X case 'H': X fmt(2, (p, "%.2d", tp->tm_hour)); X break; X case 'I': X fmt(2, (p, "%.2d", hour12)); X break; X case 'j': X fmt(3, (p, "%.3d", tp->tm_yday)); X break; X case 'm': X fmt(2, (p, "%.2d", tp->tm_mon + 1)); X break; X case 'M': X fmt(2, (p, "%.2d", tp->tm_min)); X break; X case 'p': X cpy(ap_len, ampm); X break; X case 'S': X fmt(2, (p, "%.2d", tp->tm_sec)); X break; X case 'U': X fmt(2, (p, "%.2u", y_week0)); X break; X case 'w': X fmt(2, (p, "%.2d", tp->tm_wday)); X break; X case 'W': X fmt(2, (p, "%.2u", y_week1)); X break; X case 'x': X subfmt = "%m/%d/%y"; X goto subformat; X case 'X': X subfmt = "%H:%M:%S"; X goto subformat; X case 'y': X fmt(2, (p, "%.2d", tp->tm_year)); X break; X case 'Y': X fmt(4, (p, "%.4d", 1900 + tp->tm_year)); X break; X case 'Z': X cpy(zonelen, zone); X break; X default: X /* Bad format. */ X break; X } X } X X if (p != NULL) X *p = '\0'; X return(i); X} END_OF_FILE if test 6675 -ne `wc -c <'strftime.c'`; then echo shar: \"'strftime.c'\" unpacked with wrong size! fi # end of 'strftime.c' fi echo shar: End of archive 3 \(of 17\). cp /dev/null ark3isdone MISSING="" for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have unpacked all 17 archives. rm -f ark[1-9]isdone ark[1-9][0-9]isdone else echo You still need to unpack the following archives: echo " " ${MISSING} fi ## End of shell archive. exit 0 dan ---------------------------------------------------- O'Reilly && Associates argv@sun.com / argv@ora.com Opinions expressed reflect those of the author only.