replacement utilities

This commit is contained in:
Kelvin Sherlock 2013-07-02 20:04:12 -04:00
parent f0a1240475
commit c156fd4aa2
4 changed files with 104 additions and 0 deletions

28
Tools/GetEnv.c Normal file
View File

@ -0,0 +1,28 @@
/*
*
* GetEnv variable
* read an mpw variable.
* eg: CLibraries=`mpw GetEnv CLibraries`
* (makefile) CLibraries = $(shell mpw GetEnv CLibraries)
* flags to do name = value?
*/
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
char *value;
char *name;
if (argc != 2)
{
return 1;
}
name = argv[1];
value = getenv(name);
// value == null if not defined.
if (value) puts(value);
return 0;
}

1
Tools/Help.c Normal file
View File

@ -0,0 +1 @@
/* * MPW Help utility. * * help topic * does a cat of $ShellDirectory:Help:topic */ /* * MPW 3.2 * * C Help.c -o Help.c.o -r {SymOptions} * * Link {SymOptions} -w -c 'MPS ' -t MPST Help.c.o ∂ * -sn STDIO=Main ∂ * -sn INTENV=Main ∂ * -sn %A5Init=Main ∂ * "{Libraries}"Stubs.o ∂ * "{CLibraries}"StdCLib.o ∂ * "{Libraries}"Interface.o ∂ * "{Libraries}"Runtime.o ∂ * "{Libraries}"ToolLibs.o ∂ * -o Help * */ #include <stdio.h> #include <stdlib.h> #include <string.h> char *base(char *str) { char *rv = str; char *tmp = str; if (!str) return str; for (tmp = str; *tmp; ++tmp) { char c = *tmp; if (c == ':' || c == '/') rv = tmp + 1; } return rv; } void help(char *root, char *topic) { int l; char *path; FILE *fp; // todo -- check if they're being stupid or malicious and // handle / or : chars. topic = base(topic); if (!topic || !*topic) { return; } l = strlen(root) + strlen("Help:") + strlen(topic) + 1; path = malloc(1); if (!path) { fprintf(stderr, "### Help - Memory allocation failure.\n"); return; } sprintf(path, "%sHelp:%s", root, topic); fp = fopen(path, "r"); free(path); if (!fp) { fprintf(stderr, "### Help - \"%s\" was not found.\n", topic); return; } for(;;) { char buffer[512]; int count; count = fread(buffer, 1, sizeof(buffer), fp); if (count == 0) break; fwrite(buffer, 1, count, stdout); } fwrite("\r", 1, 1, stdout); fclose(fp); } int main(int argc, char **argv) { char *root; root = getenv("ShellDirectory"); if (!root || !*root) { fprintf(stderr, "### Help - $ShellDirectory is not defined.\n"); return 1; } if (argc == 1) { help(root, "MPW"); } else { int i; for (i = 1; i < argc; ++i) { help(root, argv[i]); } } return 0; }

31
Tools/makefile Normal file
View File

@ -0,0 +1,31 @@
# makefile
Libraries=~/mpw/Libraries/Libraries
CLibraries=~/mpw/Libraries/CLibraries
LIBS = $(Libraries)/Stubs.o \
$(CLibraries)/StdCLib.o \
$(Libraries)/Interface.o \
$(Libraries)/Runtime.o \
$(Libraries)/ToolLibs.o
LDFLAGS = -w -c 'MPS ' -t MPST \
-sn STDIO=Main -sn INTENV=Main -sn %A5Init=Main
all: Help GetEnv
GetEnv: GetEnv.c.o
mpw Link $(LDFLAGS) -o $@ $^ $(LIBS)
Help: Help.c.o
mpw Link $(LDFLAGS) -o $@ $^ $(LIBS)
%.c.o : %.c
mpw SC -p $< -o $@
# GetEnv.c.o : GetEnv.c
# mpw SC -p GetEnv.c -o $@
# Help.c.o : Help.c
# mpw SC -p Help.c -o $@

44
Tools/split-help.rb Normal file
View File

@ -0,0 +1,44 @@
#!/usr/bin/env ruby -w
#
# format
# -
# name # comment
#
file = nil
state = nil
#ARGF.binmode
#ARGF.set_encoding("BINARY")
ARGF.each { |line|
line.chomp!
case state
when nil
if line == '-'
state = :name
end
when :name
if line.match(/^([A-Za-z0-F]+)\s?#?/)
state = :data
filename = $1
file = File::new("MPW.Help/#{filename}", "w")
#file.set_encoding("BINARY")
end
when :data
if line == '-'
state = :name
file = nil
else
file.puts(line)
end
end
}