02-18-2014
Quote:
Don,
Thanks for the input. Sorry, I should have been more specific. case 3 "does" print white... because I've only tested this on a tty with black bg and white fg.
When it is compiled on the Windoze side, they'll be using a black and white terminal, so it's not that big of a deal, but that's no reason for sloppy code. That said, I have about a half dozen other boxes I work on, each having their own bg / fg color combos. Just so I know what machine I'm working on. I'll have to see what output they yield.
Like I said, I haven't used C for years. This project is just getting the juices flowing. I've been pulling snippets from some of my old code. Heck, I look back at some of it, some 15+ years old, and say. I DID THAT?!?!?
For now I'm taking the KIS (Keep It Simple) approach. Your example is a bit much to digest at the moment. However, reading through it does help!
The ANSI terminal escape sequence you're using for case 3 produce black text on a white background. Having your terminal set to invert foreground and background colors makes it appear as white text on a black background when it is rendered on your screen.
I fully understand and appreciate KISS principles.
Here you have a choice between having an output function to print string arguments, an output function to print integer arguments, and an output function to print floating point arguments; or a single function that can handle all three. If you need to worry about various types of integers (int, long, long long) and floating point (float, double, long double) arguments then the processing gets more complicated. If you want to pass this routine a format string that ends with anything other than a
printf() conversion specifier character, then the processing gets considerably more complicated (as in you'd have to actually interpret the entire format string argument instead of just the last character). There is also the question of what needs to be simple? Does it need to be simple for the person writing the
output*() function (or functions), or does it need to be simple for the person using those functions? (Of course, in this case both of those might be the same person!)
Programming is full of trade-offs. I just wanted to give you some options to consider.
10 More Discussions You Might Find Interesting
1. Answers to Frequently Asked Questions
A good place to start is simple variable passing....
Passing variables from one script to another
The next level is passing a variable into a more complex command such as using a variable in a sed command. There are some simple quoting techniques that are very general. These are mentioned... (0 Replies)
Discussion started by: Perderabo
0 Replies
2. Shell Programming and Scripting
hi,
i am passing around 14 parameters for a script
a=$1
b=$2
c=$3
d=$4
e=$5
f=$6
g=$7
h=$8
i=\"${9}\"
shift
j=\"${1}\"
still for j it is displaying the 1st parameter value..how to make it take the 10th parameter (2 Replies)
Discussion started by: dnat
2 Replies
3. Shell Programming and Scripting
Hi all,
My simple AWK code does C = A - B
If C can be a negative number, how awk printf formating handles it using string format specifier.
Thanks in advance
Kanu
:confused: (9 Replies)
Discussion started by: kanu_pathak
9 Replies
4. Shell Programming and Scripting
seems simple but i've not been successfull in adding the value of a Variable to a every line of a file using AWK & printf
i've come up with the following, but it's not working.:mad:
--- mydatafile.dat
e.g. of data in file:
cau_actvty_fa_lrf.ksh
fan_soco_fa.ksh
ny_sum_lst.ksh... (4 Replies)
Discussion started by: danmauer
4 Replies
5. Shell Programming and Scripting
Hi I'm having a problem with converting a file:
ID X
1 7
1 8
1 3
2 5
2 7
2 2
To something like this:
ID X1 X2 X3
1 7 8 3
2 5 7 2
I've tried the following loop:
for i in `cat tst.csv| awk -F "," '{print $1}'| uniq`;do grep -h $i... (4 Replies)
Discussion started by: flotsam
4 Replies
6. UNIX for Dummies Questions & Answers
Is there a way to make these 2 numbers - $482477.37 and $1875000.00
look like $482,477.37 and $1,875,000.00 with printf? (4 Replies)
Discussion started by: nickg
4 Replies
7. Shell Programming and Scripting
Hi Friends,
I am trying to insert lines of the below format in a file:
# x3a4914 Joe 2010/04/07
# seh Lane 2010/04/07
# IN01379 Larry 2010/04/07
I am formatting the strings as follows using awk printf:
awk 'printf "# %s %9s %18s\n", $2,$3,$4}'
... (2 Replies)
Discussion started by: sugan
2 Replies
8. Shell Programming and Scripting
Getting the below error while executing this. Able to run the below commands Individually.
#!/bin/bash
a=$(printf "%d\n" 0x01E);
b=$(printf "%d\n" 0x01A);
echo $a
echo $b
c=`expr $a - $b`
echo $c
syntax error at line 2: `a=$' unexpected (2 Replies)
Discussion started by: sai_1712
2 Replies
9. Shell Programming and Scripting
Hi All,
I am attempting to create a fixed length tilde delimited file using printf.
The variables are initialized to fixed length blank spaces
a=' '
b=' '
c=' '
d=' '
Sometimes the variable might contain values and sometimes they are... (5 Replies)
Discussion started by: angie1234
5 Replies
10. Shell Programming and Scripting
Trying to do so
echo "111:222:333" |awk -F: '{system("export TESTO=" $2)}'But it doesn't work (2 Replies)
Discussion started by: urello
2 Replies
LEARN ABOUT DEBIAN
gammu-smsd-run
GAMMU-SMSD-RUN(7) Gammu GAMMU-SMSD-RUN(7)
NAME
gammu-smsd-run - documentation for RunOnReceive directive
DESCRIPTION
Gammu SMSD can be configured by RunOnReceive directive (see gammu-smsdrc for details) to run defined program after receiving every message.
It can receive single message or more messages, which are parts of one multipart message.
This parameter is executed through shell, so you might need to escape some special characters and you can include any number of parameters.
Additionally parameters with identifiers of received messages are appended to the command line. The identifiers depend on used service
backend, typically it is ID of inserted row for database backends or file name for file based backends.
Gammu SMSD waits for the script to terminate. If you make some time consuming there, it will make SMSD not receive new messages. However to
limit breakage from this situation, the waiting time is limited to two minutes. After this time SMSD will continue in normal operation and
might execute your script again.
Note All input and output file descriptors are closed when this program is invoked, so you have to ensure to open files on your own.
ENVIRONMENT
program is executed with environment which contains lot of information about the message. You can use it together with NULL service (see
gammu-smsd-null) to implement completely own processing of messages.
Global variables
SMS_MESSAGES
Number of physical messages received.
DECODED_PARTS
Number of decoded message parts.
Per message variables
The variables further described as SMS_1_... are generated for each physical message, where 1 is replaced by current number of message.
SMS_1_CLASS
Class of message.
SMS_1_NUMBER
Sender number.
SMS_1_TEXT
Message text. Text is not available for 8-bit binary messages.
Per part variables
The variables further described as DECODED_1_... are generated for each message part, where 1 is replaced by current number of part. Set
are only those variables whose content is present in the message.
DECODED_1_TEXT
Decoded long message text.
DECODED_1_MMS_SENDER
Sender of MMS indication message.
DECODED_1_MMS_TITLE
title of MMS indication message.
DECODED_1_MMS_ADDRESS
Address (URL) of MMS from MMS indication message.
DECODED_1_MMS_SIZE
Size of MMS as specified in MMS indication message.
EXAMPLES
Activating RunOnReceive
To activate this feature you need to set RunOnReceive in the gammu-smsdrc.
[smsd]
RunOnReceive = /path/to/script.sh
Processing messages from the files backend
Following script (if used as RunOnReceive handler) passes message data to other program. This works only with the gammu-smsd-files.
#!/bin/sh
INBOX=/path/to/smsd/inbox
PROGRAM=/bin/cat
for ID in "$@" ; do
$PROGRAM < $INBOX/$ID
done
Passing message text to program
Following script (if used as RunOnReceive handler) passes message text and sender to external program.
#!/bin/sh
PROGRAM=/bin/echo
for i in `seq $SMS_MESSAGES` ; do
eval "$PROGRAM "${SMS_${i}_NUMBER}" "${SMS_${i}_TEXT}""
done
Passing MMS indication parameters to external program
Following script (if used as RunOnReceive handler) will write information about each received MMS indication to the log file. Just replace
echo command with your own program to do custom processing.
#!/bin/sh
if [ $DECODED_PARTS -eq 0 ] ; then
# No decoded parts, nothing to process
exit
fi
if [ "$DECODED_1_MMS_ADDRESS" ] ; then
echo "$DECODED_1_MMS_ADDRESS" "$DECODED_1_MMS_SENDER" "$DECODED_1_MMS_TITLE" >> /tmp/smsd-mms.log
fi
Processing message text in Python
Following script (if used as RunOnReceive handler) written in Python will concatenate all text from received message:
#!/usr/bin/python
import os
import sys
numparts = int(os.environ['DECODED_PARTS'])
# Are there any decoded parts?
if numparts == 0:
print('No decoded parts!')
sys.exit(1)
# Get all text parts
text = ''
for i in range(1, numparts + 1):
varname = 'DECODED_%d_TEXT' % i
if varname in os.environ:
text = text + os.environ[varname]
# Do something with the text
print('Number %s have sent text: %s' % (os.environ['SMS_1_NUMBER'], text))
AUTHOR
Michal iha <michal@cihar.com>
COPYRIGHT
2009-2012, Michal iha <michal@cihar.com>
1.31.90 February 24, 2012 GAMMU-SMSD-RUN(7)