From: shane@utdallas.edu (Shane Davis)
Subject: Re: Stupid macro tricks...
Reply-To: shane@utdallas.edu
Organization: The Univ. of Texas at Dallas, ACC
Date: Mon, 25 Jan 1993 18:36:15 GMT

In article <C1E75L.7J9@csugrad.cs.vt.edu>, lkestel@csugrad.cs.vt.edu (Lawrence Kesteloot) writes:
|> daffnelr@mentor.cc.purdue.edu (Throatwarbler Mangrove) writes:
|> 
|> 
|> >  Hey.. anyone out there got really
|> >ugly/complicated/elegant/interesting macros in any of their programs?
|> 
|> This isn't actually my own program, but it's ugly enough that I thought
|> you might like to see it.  It's from BSD Net/2, from the kernel malloc
|> source code:
|> 

Here's an ugly macro...in fact, every macro written for S/370 is ugly. I
include it for variety's sake on this group (always C & UNIX!).

--Shane

         MACRO                                                          GEN0001
&LABEL   GENCMD &ABBR=,&NEXTBL=,&PRIV=,&ROUTINE=,&USERH=,&PARM=         GEN0002
.*                                                                      GEN0003
.********************************************************************** GEN0004
.* GENCMD - generate command/function tables for use with UTDCMD      * GEN0005
.* parsing routines. The command or function name is specified by the * GEN0006
.* label of the macro.                                                * GEN0007
.*                                                                    * GEN0008
.*        ABBR=n     - minimum abbreviation for this keyword          * GEN0009
.*        NEXTBL=v   - label of subfunction table to parse next       * GEN0010
.*        PRIV=n     - privilege level necessary to use this function * GEN0011
.*                     (not checked or used by UTDCMD)                * GEN0012
.*        ROUTINE=v  - address of routine to process this command     * GEN0013
.*                     (transfer of control NOT made by UTDCMD)       * GEN0014
.*        USERH=x    - user halfword (e.g., parameter to ROUTINE)     * GEN0015
.*        PARM=(list)- up to three parameters for the function, typed * GEN0016
.*                     as: ANY - any characters; NUM - numeric only;  * GEN0017
.*                     ANUM - alphanumeric; LINE - remainder of line  * GEN0018
.*                     ALPHA - alhpabetic only; OPT+any-of-the-above  * GEN0019
.*                     (i.e., OPTNUM) makes the parameter optional.   * GEN0020
.*                                                                    * GEN0021
.* NEXTBL and PARM are mutually exclusive. Register operands are not  * GEN0022
.* permitted in any parameter to the macro. PRIV, USERH and ROUTINE   * GEN0023
.* are for use by the program calling UTDCMD to process the commands  * GEN0024
.* and are exclusively for that program's convenience.                * GEN0025
.********************************************************************** GEN0026
.*                                                                      GEN0027
         LCLC  &TORP                                                    GEN0028
         LCLA  &TAB                                                     GEN0029
         LCLC  &TAD                                                     GEN0030
         LCLC  &TCL                                                     GEN0031
         LCLC  &TUH                                                     GEN0032
         LCLA  &NPARM                                                   GEN0033
         LCLA  &XPARM                                                   GEN0034
         LCLA  &PARMASK                                                 GEN0035
         LCLA  &PMULT                                                   GEN0036
         LCLC  &PARTEMP                                                 GEN0037
.*                                                                      GEN0038
         AIF   ('&ABBR' NE '').GOTABBR                                  GEN0039
         AIF   ('&ABBR' NE '').GOTABBR                                  GEN0039
&TAB     SETA  K'&LABEL                                                 GEN0040
         AGO   .ISUSERH                                                 GEN0041
.GOTABBR ANOP                                                           GEN0042
&TAB     SETA  &ABBR                                                    GEN0043
.*                                                                      GEN0044
.ISUSERH AIF   ('&USERH' EQ '').ISPARM                                  GEN0045
         AIF   ('&NEXTBL' EQ '').ISPARM                                 GEN0046
         MNOTE 8,'''USERH'' AND ''NEXTBL'' ARE MUTUALLY EXCLUSIVE'      GEN0047
         MEXIT                                                          GEN0048
.ISPARM  AIF   ('&PARM' EQ '').CHKTBL                                   GEN0049
&NPARM   SETA  N'&PARM                                                  GEN0050
         AIF   ('&NEXTBL' EQ '').CHKPARM                                GEN0051
         MNOTE 8,'''PARM'' AND ''NEXTBL'' ARE MUTUALLY EXCLUSIVE'       GEN0052
         MEXIT                                                          GEN0053
.*                                                                      GEN0054
.CHKPARM AIF   (N'&PARM LE 3).NPARMOK                                   GEN0055
         MNOTE 3,'''PARM'' SUBLIST TOO LONG; FIRST 3 ACCEPTED'          GEN0056
&NPARM   SETA  3                                                        GEN0057
.*                                                                      GEN0058
.NPARMOK ANOP                                                           GEN0059
&XPARM   SETA  1                                                        GEN0060
&PMULT   SETA  1                                                        GEN0061
&PARMASK SETA  0                                                        GEN0062
.*                                                                      GEN0063
.PARMTOP ANOP                                                           GEN0064
&PARTEMP SETC  '&PARM(&XPARM)'                                          GEN0065
         AIF   ('&PARTEMP'(1,3) NE 'OPT').CHKALPH                       GEN0066
&PARMASK SETA  16*&PMULT+&PARMASK                                       GEN0067
&PARTEMP SETC  '&PARM(&XPARM)'(4,5)                                     GEN0068
.CHKALPH AIF   ('&PARTEMP' NE 'ALPHA').CHKNUM                           GEN0069
&PARMASK SETA  &PMULT+&PARMASK                                          GEN0070
         AGO   .NXTPARM                                                 GEN0071
.CHKNUM  AIF   ('&PARTEMP' NE 'NUM').CHKANUM                            GEN0072
&PARMASK SETA  2*&PMULT+&PARMASK                                        GEN0073
         AGO   .NXTPARM                                                 GEN0074
.CHKANUM AIF   ('&PARTEMP' NE 'ANUM').CHKSPEC                           GEN0075
&PARMASK SETA  3*&PMULT+&PARMASK                                        GEN0076
         AGO   .NXTPARM                                                 GEN0077
.CHKSPEC AIF   ('&PARTEMP' NE 'SPEC').CHKANY                            GEN0078
&PARMASK SETA  4*&PMULT+&PARMASK                                        GEN0079
         AGO   .NXTPARM                                                 GEN0080
.CHKANY  AIF   ('&PARTEMP' NE 'ANY').CHKLINE                            GEN0081
&PARMASK SETA  7*&PMULT+&PARMASK                                        GEN0082
         AGO   .NXTPARM                                                 GEN0083
.CHKLINE AIF   ('&PARTEMP' NE 'LINE').PARMBAD                           GEN0084
&PARMASK SETA  8*&PMULT+&PARMASK                                        GEN0085
.NXTPARM ANOP                                                           GEN0086
&XPARM   SETA  &XPARM+1                                                 GEN0087
&PMULT   SETA  &PMULT*256                                               GEN0088
         AIF   (&XPARM LE &NPARM).PARMTOP                               GEN0089
.*                                                                      GEN0090
&TORP    SETC  'F''&PARMASK'''                                          GEN0091
         AGO   .TBLOK                                                   GEN0092
.*                                                                      GEN0093
.PARMBAD MNOTE 4,'INVALID ''PARM'' SPECIFICATION - PARAMETER IGNORED'   GEN0094
&TORP    SETC  'F''0'''                                                 GEN0095
         AGO   .TBLOK                                                   GEN0096
.*                                                                      GEN0097
.CHKTBL  ANOP                                                           GEN0098
&TORP    SETC  'AL4(&NEXTBL)'                                           GEN0099
         AIF   ('&NEXTBL' NE '').TBLOK                                  GEN0100
&TORP    SETC  'F''0'''                                                 GEN0101
.*                                                                      GEN0102
.TBLOK   ANOP                                                           GEN0103
&TAD     SETC  'V(&ROUTINE)'                                            GEN0104
&TCL     SETC  '&PRIV'                                                  GEN0105
&TUH     SETC  '&USERH'                                                 GEN0106
         AIF   ('&ROUTINE' NE '').ADDROK                                GEN0107
&TAD     SETC  'F''0'''                                                 GEN0108
.ADDROK  AIF   ('&PRIV' NE '').PRIVOK                                   GEN0109
&TCL     SETC  '0'                                                      GEN0110
.PRIVOK  AIF   ('&USERH' NE '').USERHOK                                 GEN0111
&TUH     SETC  '0'                                                      GEN0112
.*                                                                      GEN0113
.USERHOK DC     CL8'&LABEL'                                             GEN0114
         DC     &TORP                                                   GEN0115
         DC     &TAD                                                    GEN0116
         DC     X'&TAB'                                                 GEN0117
         DC     X'&TCL'                                                 GEN0118
         DC     H'&TUH'                                                 GEN0119
         MEND                                                           GEN0120