From: wolinsky@isys.com (Jeff Wolinsky)
Newsgroups: comp.windows.open-look
Subject: DevGuide item arrays
Date: 15 Oct 92 18:05:57 GMT


Bill Leue (leue@crd.ge.com) writes:

    ...It would be quite handy if you could tell DevGuide, using
    some kind of "duplicate" command, that you wanted to replicate
    an item 'N' times and put the handles into an array...

The following script kinda does that.  All feedback is welcomed.

- Jeff

/---------------------------------------------------------------------------\
|                     | Isys Controls, Inc.      |                          |
| Jeffrey Wolinsky    | 2417 Mariner Square Loop | The sooner               |
| Software Engineer   | Alameda, California      |    you get behind...     |
|                     | 94501  USA               |                          |
| wolinsky@isys.com   |                          | the more time            |
| uunet!isys!wolinsky | Tel: (510) 865-9882      |    you have to catch up. |
|                     | Fax: (510) 865-9927      |                          |
\---------------------------------------------------------------------------/

-----

#!/bin/sh
###################################################################
#
#  guidearray  (a shell script)
#
#  Date:   10 October 1992
#  Author: Jeffrey Wolinsky  (wolinsky@isys.com)
#
#  Portions Copyright (C) 1992 Isys Controls, Inc.
#
#  Permission is granted to use, copy, and modify this software,
#  provided this original copyright notice is retained.
#
###################################################################
#
# This script takes DevGuide-generated _ui.c and _ui.h files and
# turns specially named DevGuide items into array elements, making
# it much easier to reference multiple, similar-purpose gui items.
#
# Calling the script:
#
#           guidearray guidefile
#
#      "guidefile" is the name of your .G file without the ".G"
#      extension.
#
# Output:
#
#      The script dumps its output back into the _ui.c and _ui.h
#      files, although this can (obviously) be modified to suit
#      your needs.
# 
# How to use this stuff:
#
#  (1) Name the first (zero index) item to be arrayed "foo__0_m",
#      where "foo" is the array name and "m" is the number of array
#      elements that "foo" will need.  (Note the double underscores
#      after "foo", and the single underscore after zero.)
#
#  (2) Name subsequent items to be arrayed "foo__n", where "n" is
#      index of the item in the "foo" array.  (Note the double
#      underscores after "foo".)
#
# For example:
#
#      If you have three buttons you want arrayed together, you
#      could name the first button "myButton__0_3", the second
#      "myButton__1", and the third "myButton__2".  After running
#      this script, your code can reference the second button
#      as "instance->myButton[1]".  Nifty, huh?
#
# A nice thing:
#
#      When you duplicate items in DevGuide, items whose names end
#      in numbers are duplicated with the number replaced by the
#      lowest number (>= 1) which would make the name unique.
#
#      Thus, if you duplicate (copy & paste) any group of array
#      named items (except the zero index "size" item), DevGuide
#      will automatically increment the "array index" kludge value.
#
# Some not-so-nice things:
#
#  (1) This script is only tested for DevGuide 1.1 and 3.0
#      generating XView 2.0 and 3.0 code respectively.
#
#  (2) This script in no way modifies the generated _stubs.c file.
#      I haven't looked at how to deal with _stubs.c or DevGuide
#      3.0 auto-connection issues.  Any feedback is welcome.
#
#  (3) This script is heavily reliant on the exact syntax of code
#      generated by 'gxv'.  If Sun modifies the code generation
#      down the line, this script might break.
#
#  (4) The _ui.c code size is not reduced to take advantage of
#      the creation of similar items.  This would be very hard.
#      Therefore, each item is created the same old explicit way.
#
#  (5) Working the script into a 'make' file can be complicated.
#      Make issues are so varied, that this is left as the
#      proverbial "exercise to the reader".
#
#  (6) Error checking is nil.
#
###################################################################

echo -n "arraying guide file '$1'..."

#
# In the _ui.c file, perform the following conversions which change
# items to array members:
#
#	__0_m)    ->   [0])
#	__n)      ->   [n])
#	__0_m =   ->   [0] =
#	__n =     ->   [n] =
#

sed \
    -e "s/__0_[0-9][0-9]*)/[0])/" \
    -e "s/__\([1-9][0-9]*\))/[\1])/" \
    -e "s/__0_[0-9][0-9]* =/[0] =/" \
    -e "s/__\([1-9][0-9]*\) =/[\1] =/" \
    $1_ui.c > .sedtmp
mv .sedtmp $1_ui.c

#
# In the _ui.h file, perform the following conversions which create
# an array of items, deleting individual declarations:
#
#	__0_m;   ->   [m];
#	__n;     ->   entire line deleted
#

sed \
    -e "s/__0_\([0-9][0-9]*\);/[\1];/" \
    -e "/__[1-9][0-9]*;/d" \
    $1_ui.h > .sedtmp
mv .sedtmp $1_ui.h

echo " done."