Add another program for 2001/anonymous

This sings a different counting song, Ten in the Bed. It uses another C
feature (a char *[]) that the Ten Green Bottles does not use. This is
for fun as well as to show another program (with a different C feature)
that the program works on, again assuming -m32 is allowed.

Instead of using numbers it uses strings (as expected with a char *[])
in the singing.

This was for fun (and to see if the program would work on arrays) after
I remembered the song in a comment on GitHub - about the Ten Green
Bottles song.
This commit is contained in:
Cody Boone Ferguson committed 2023-05-21 09:09:54 -07:00
1 parent 1b9ea65e05
commit 93684cfc19
4 files changed
+64 -2

No files matched your search

+2
View File
@@ -6,3 +6,5 @@ ten.bak.txt
ten.od
ten.txt
anonymous.ten.64
anonymous.bed
anonymous.bed.64
+23 -2
View File
@@ -117,7 +117,7 @@ PROG= ${ENTRY}
#
OBJ= ${PROG}.o
DATA=
TARGET= ${PROG} ${PROG}.ten ${PROG}.ten.64
TARGET= ${PROG} ${PROG}.ten ${PROG}.ten.64 ${PROG}.bed ${PROG}.bed.64
#
ALT_OBJ= ${PROG}.ten.64.o
ALT_TARGET= ${PROG}.ten.64
@@ -150,7 +150,7 @@ ${PROG}.ten: ${PROG}.ten.c
@echo "If you want to use it where this is not possible e.g. with a Mac, say to"
@echo "use by itself, try:"
@echo
@echo " ${CC} $< -o $@"
@echo " make anonymous.ten.64"
@echo
@echo "but running ${PROG} on the resulting binary will crash."
@echo
@@ -162,6 +162,27 @@ ${PROG}.ten.64: ${PROG}.ten.c
@echo "lets you see the supplementary program in action."
${CC} ${CFLAGS} $< -o $@ ${LIBS}
${PROG}.bed: ${PROG}.bed.c
@echo "WARNING: ${PROG}.bed.c must be compiled as 32-bit to use with the entry itself;"
@echo "this is because the program works on 32-bit binaries. If you cannot use -m32 this"
@echo "will NOT work!"
@echo
@echo "If you want to use it where this is not possible e.g. with a Mac, say to"
@echo "use by itself, try:"
@echo
@echo " make anonymous.bed.64"
@echo
@echo "but running ${PROG} on the resulting binary will crash."
@echo
${CC} ${CFLAGS} -m32 $< -o $@ ${LIBS}
${PROG}.bed.64: ${PROG}.bed.c
@echo "WARNING: the file created by this rule will NOT work with the entry itself;"
@echo "this is because it works ONLY on 32-bit ELF binaries! This however at least"
@echo "lets you see the supplementary program in action."
${CC} ${CFLAGS} $< -o $@ ${LIBS}
# alternative executable
#
alt: data ${ALT_TARGET}
+16
View File
@@ -67,12 +67,28 @@ Finally to see from start to finish:
git diff d2a42f42e8f477f29e9d5ed09ce2bb349eaf7397..4bc03de321612869aebf855850c6500df95cb6ef anonymous.c
```
Cody also added a [program](anonymous.bed.c) like [anonymous.ten.c](anonymous.ten.c)
[Ten Green Bottles](https://en.wikipedia.org/wiki/Ten_Green_Bottles) but which
sings [Ten in the Bed](https://allnurseryrhymes.com/ten-in-the-bed/). Why? For
fun and so that there's another program that is a bit different (it uses a `char
*[]` array for example) that this program will still work on. To use:
```sh
make anonymous.bed # if able to use -m32
./anonymous anonymous.bed
make anonymous.bed.64 # if unable to use -m32
./anonymous.bed.64
```
Thank you Cody for your assistance!
## Try:
```sh
./try.me.sh
./anonymous anonymous.bed # if able to use -m32
```
What happens if the x86 program has already been modified by this program? The
+23
View File
@@ -0,0 +1,23 @@
#include <stdio.h>
char *bed[] = { "TEN", "NINE", "EIGHT", "SEVEN", "SIX", "FIVE", "FOUR", "THREE", "TWO", "ONE" };
void sing(int persons) {
printf("There %s %s in the bed and the little one said, '%s'\n",
persons==9?"was":"were",
bed[persons],persons==9?"Good night!":"Roll over, roll over!");
if (persons != 9)
printf("So they all rolled over and one fell out...\n");
}
int main() {
int persons = 0;
while(persons<10) {
sing(persons++);
puts("");
}
return 0;
}