I've had a problem with #defines which has been nagging me for years.
It wasn't a big problem, and it always struck me that it would be a radical chore to solve it, and I'd never ever heard anyone else complain about it, and... well, anyway, I finally got around to doing something, and I have a solution, but you Awkward guys could maybe help me make it really polished.
I have a C/Objc program with some defines in a file like this:
The project also has some bash scripts which must use the same exact "variables". Until now, I've been copy & pasting the string Supercalifragilisticexpialidocious from my ObjC.h file into my bash script(s)... and that doesn't seem like a BIG deal, but then I forgot, the other day... ( It so happens that the actual "spelling", so to speak, of Supercalifragilisticexpialidocious has changed many times in my current app, and so... here we are. )
I wanted to have just one doggone declaration of Supercalifragilisticexpialidocious somewhere, and then both my ObjC code and my bash scripts would refer to that one declaration.
So I mostly have it figgered out; I have the following bash script:
So, performed on my ObjC header above, it spits out:
If I call eval() on the result of the script, like this:
Then Voila! kMyKillerAppIdentity is now a bona fide bash variable with the proper value.
But you can see where I'd like go just one step further-- I would like to avoid having to call "eval" at all, ( from outside )-- I would like the bash script to not only eval the assignment string(s) that I generate, but also, darn it, because it's a script, I need to call export to get the variable and its value pushed up out of the script to the calling environment.
IOW, can I somehow get the value of Awk's $2 and then call bash's export command on it? At this point, I've stretched my bash / Awk competency six counties past the limit... If you can help me do this, or there's some completely different other weird way... tHnaks!
It wasn't a big problem, and it always struck me that it would be a radical chore to solve it, and I'd never ever heard anyone else complain about it, and... well, anyway, I finally got around to doing something, and I have a solution, but you Awkward guys could maybe help me make it really polished.
I have a C/Objc program with some defines in a file like this:
Code:
//
// kMyKillerApp.h
// MyKillerApp
//
// Created by Senior Programmer on 3/9/14.
// Copyright 2014 ComTech. All rights reserved.
#pragma once
#define kMyKillerAppIdentity Supercalifragilisticexpialidocious
#define kMyKillerAppIdLength 34
//#define kMyKillerAppBaseIdLength yeah,nevermind
The project also has some bash scripts which must use the same exact "variables". Until now, I've been copy & pasting the string Supercalifragilisticexpialidocious from my ObjC.h file into my bash script(s)... and that doesn't seem like a BIG deal, but then I forgot, the other day... ( It so happens that the actual "spelling", so to speak, of Supercalifragilisticexpialidocious has changed many times in my current app, and so... here we are. )
I wanted to have just one doggone declaration of Supercalifragilisticexpialidocious somewhere, and then both my ObjC code and my bash scripts would refer to that one declaration.
So I mostly have it figgered out; I have the following bash script:
Code:
#!/bin/bash
# Takes lines like:
#define kFinkNottle Gussie
# from the file passed in $1, and echos back space-separated "lines" like "kFinkNottle=Gussie".
echo `awk '/^#define/ {print $2 "=" $3}' "$1"`
So, performed on my ObjC header above, it spits out:
Code:
kMyKillerAppIdentity=Supercalifragilisticexpialidocious kMyKillerAppIdLength=34
If I call eval() on the result of the script, like this:
Code:
eval `./bridgeFromDefineToBash kMyKillerApp.h`
Then Voila! kMyKillerAppIdentity is now a bona fide bash variable with the proper value.
But you can see where I'd like go just one step further-- I would like to avoid having to call "eval" at all, ( from outside )-- I would like the bash script to not only eval the assignment string(s) that I generate, but also, darn it, because it's a script, I need to call export to get the variable and its value pushed up out of the script to the calling environment.
IOW, can I somehow get the value of Awk's $2 and then call bash's export command on it? At this point, I've stretched my bash / Awk competency six counties past the limit... If you can help me do this, or there's some completely different other weird way... tHnaks!