Skip to content

Commit

Permalink
Merge pull request #12 from jlp765/enhancement/more
Browse files Browse the repository at this point in the history
Enhancement/more
  • Loading branch information
noyesno authored Jul 19, 2021
2 parents f42322a + 19d7c66 commit 5732da8
Show file tree
Hide file tree
Showing 59 changed files with 4,077 additions and 2,258 deletions.
2 changes: 1 addition & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ clean:
cd awka; $(MAKE) clean
cd lib; $(MAKE) clean
cd test; $(MAKE) clean
cd benchmark; $(MAKE) clean

distclean: clean
rm -f config.h Makefile lib/Makefile awka/Makefile test/Makefile benchmark/Makefile \
config.status config.log config.cache
rm -f defines.out maxint.out
rm -f benchmark/*.c benchmark/core benchmark/*.o benchmark/x* benchmark/*.out

configure: configure.in awka.ac.m4
autoconf
Expand Down
20 changes: 10 additions & 10 deletions awka/awka.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ isarray(char *var)
-----------------------------------------------------------------------------
*/

static char* tmpfile_prefix(const char *pattern){
static char* tmpfile_prefix(const char *pattern) {
char tmp_file[512];
strcpy(tmp_file, pattern);
int fd = mkstemp(tmp_file);
Expand All @@ -158,7 +158,7 @@ static char* tmpfile_prefix(const char *pattern){
return file_path;
}

static int awka_output_file(int awka_tmp, char *uoutfile, char **c_file, char **outfile){
static int awka_output_file(int awka_tmp, char *uoutfile, char **c_file, char **outfile) {
char *outfile_prefix = NULL;
char *outfile_suffix;

Expand Down Expand Up @@ -194,7 +194,7 @@ static int awka_output_file(int awka_tmp, char *uoutfile, char **c_file, char **
return 1;
}

static char* awka_build_compile_command(char *c_file, char *outfile){
static char* awka_build_compile_command(char *c_file, char *outfile) {
char *cmd;
int incd_len=0, libd_len=0, libf_len=0;

Expand Down Expand Up @@ -235,7 +235,7 @@ static char* awka_build_compile_command(char *c_file, char *outfile){
return cmd;
}

static int awka_do_compile(char *c_file, char *outfile){
static int awka_do_compile(char *c_file, char *outfile) {
char *cmd;
cmd = awka_build_compile_command(c_file, outfile);

Expand All @@ -258,7 +258,7 @@ static int awka_do_compile(char *c_file, char *outfile){
return 1;
}

static int awka_do_exec(char *outfile){
static int awka_do_exec(char *outfile) {
int len = strlen(outfile);
for (int i=0; i<exe_argc; i++)
len += strlen(exe_argv[i]) + 2;
Expand Down Expand Up @@ -291,7 +291,7 @@ int main(int argc, char *argv[])

parse();

if (!prog_no){
if (!prog_no) {
awka_error("Sorry, program was not parsed successfully.\n");
return -1;
}
Expand All @@ -308,7 +308,7 @@ int main(int argc, char *argv[])
if (do_compile) {
awka_output_file(awka_tmp, uoutfile, &c_file, &outfile);
outfp = fopen(c_file, "w");
if (!outfp){
if (!outfp) {
awka_error("Failed to open %s to write.\n", c_file);
return -1;
}
Expand All @@ -319,18 +319,18 @@ int main(int argc, char *argv[])

if (do_compile) {
int compile_succ = awka_do_compile(c_file, outfile);
if(!compile_succ){
if (!compile_succ) {
awka_error("Awka error: compile failed.\n");
return -1;
}
}

if (do_exec){
if (do_exec) {
awka_do_exec(outfile);
}

if ( do_compile || do_exec ) {
if(awka_tmp){
if (awka_tmp) {
remove(outfile);
}
remove(c_file);
Expand Down
6 changes: 4 additions & 2 deletions awka/awka_exe.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ char * awka_nullfunc(int, int *, char *);
char * awka_math(int, int *, char *);
char * awka_index(int, int *, char *);
char * awka_colon(int, int *, char *);
char * awka_length(int, int *, char *);
char * awka_bi_length(int, int *, char *);
char * awka_substr(int, int *, char *);
char * awka_asort(int, int *, char *);
char * awka_alength(int, int *, char *);
Expand Down Expand Up @@ -282,7 +282,7 @@ struct a_sc code[] = {
{ "int", awka_math, a_INT, _BI_INT, FALSE, 0, },
{ "isarray", awka_builtin, _ISARRAY, _BI_ISARRAY, FALSE, 0, },
{ "left", awka_builtin, _LEFT, _BI_LEFT, FALSE, 2, },
{ "length", awka_length, _LENGTH, _BI_LENGTH, FALSE, 1, },
{ "length", awka_bi_length, _LENGTH, _BI_LENGTH, FALSE, 1, },
{ "lgamma", awka_math, _LGAMMA, _BI_LGAMMA, FALSE, 0, },
{ "localtime", awka_builtin, a_LOCALTIME, _BI_LOCALTIME, FALSE, 2, },
{ "log", awka_math, _LOG, _BI_LOG, FALSE, 0, },
Expand Down Expand Up @@ -321,6 +321,7 @@ struct a_sc code[] = {
{ "toupper", awka_tocase, _TOUPPER, _BI_TOCASE, FALSE, 2, },
{ "trim", awka_builtin, _TRIM, _BI_TRIM, FALSE, 2, },
{ "trunc", awka_math, _TRUNC, _BI_TRUNC, FALSE, 0, },
{ "typeof", awka_builtin, _TYPEOF, _BI_TYPEOF, FALSE, 0, },
{ "xor", awka_builtin, _XOR, _BI_XOR, FALSE, 1 },
{ "fsize", awka_builtin, _FSIZE, -1, FALSE, 1, },
{ "fseek", awka_builtin, _FSEEK, -1, FALSE, 1, },
Expand Down Expand Up @@ -355,6 +356,7 @@ struct a_sc ext_funcs[] = {
{ "time", awka_builtin, a_TIME, _BI_TIME, FALSE, 1, },
{ "totitle", awka_tocase, _TOTITLE, _BI_TOCASE, FALSE, 2, },
{ "trim", awka_builtin, _TRIM, _BI_TRIM, FALSE, 2, },
{ "typeof", awka_builtin, _TYPEOF, _BI_TYPEOF, FALSE, 0, },
{ "xor", awka_builtin, _XOR, _BI_XOR, FALSE, 1, },
{ "fsize", awka_builtin, _FSIZE, -1, FALSE, 1, },
{ "fseek", awka_builtin, _FSEEK, -1, FALSE, 1, },
Expand Down
19 changes: 17 additions & 2 deletions awka/bi_funct.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
/* global for the disassembler */
char *bi_names[] =
{
"xxyyzz",
"length",
"index",
"substr",
Expand Down Expand Up @@ -98,12 +99,14 @@ char *bi_names[] =
"mod",
"pow",
"isarray",
"typeof",
NULL
};

BI_REC bi_funct[] =
{ /* info to load builtins */

"xxyyzz", bi_length, 1, 1,
"length", bi_length, 0, 1, /* special must come first */
"index", bi_index, 2, 2,
"substr", bi_substr, 2, 3,
Expand Down Expand Up @@ -149,6 +152,7 @@ BI_REC bi_funct[] =
"mod", bi_mod, 2, 2,
"pow", bi_pow, 2, 2,
"isarray", bi_isarray, 1, 1,
"typeof", bi_typeof, 1, 1,
(char *) 0, (PF_CP) 0, 0, 0} ;

char
Expand Down Expand Up @@ -177,13 +181,17 @@ bi_funct_init()

/* length is special (posix bozo) */
stp = insert(bi_funct->name) ;
stp->type = ST_LENGTH ;
stp->type = ST_NONE;
//stp->type = ST_LENGTH ;
stp->stval.bip = bi_funct ;

for (p = bi_funct + 1; p->name; p++)
{
stp = insert(p->name) ;
stp->type = ST_BUILTIN ;
if (strcmp(p->name, "length") == 0)
stp->type = ST_LENGTH ;
else
stp->type = ST_BUILTIN ;
stp->stval.bip = p ;
}

Expand Down Expand Up @@ -781,3 +789,10 @@ bi_isarray(sp)
{
return sp ;
}

CELL *
bi_typeof(sp)
register CELL *sp ;
{
return sp ;
}
3 changes: 2 additions & 1 deletion awka/bi_funct.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ CELL *PROTO( bi_alength, (CELL *) ) ;
CELL *PROTO( bi_argcount, (CELL *) ) ;
CELL *PROTO( bi_argval, (CELL *) ) ;

CELL *PROTO( bi_isarray, (CELL *) ) ;
CELL *PROTO( bi_isarray, (CELL *) ) ;
CELL *PROTO( bi_typeof, (CELL *) ) ;

char bi_funct_find(char *) ;

Expand Down
21 changes: 11 additions & 10 deletions awka/code.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,25 +290,26 @@ void PROTO(dump_code, (void)) ;
#define _TOUPPER 173
#define _TRIM 174
#define _TRUNC 175
#define _TYPEOF 176


#define _XOR 176 // was 150
#define _FSIZE 177
#define _FSEEK 178
#define _FTELL 179
#define _XOR 177 // was 150
#define _FSIZE 178
#define _FSEEK 179
#define _FTELL 180

#define CODE_MIN 0
#define CODE_MAX 100

#define BI_MIN 101
// # define BI_MAX 149 // TODO: use 153 ? Is original 149 a bug?
#define BI_MAX 176
#define BI_MAX 177


#define _FUNCTION 180 // was 154
#define _BEGIN 181
#define _MAIN 182
#define _END 183
#define END_CODE 184
#define _FUNCTION 181 // was 154
#define _BEGIN 182
#define _MAIN 183
#define _END 184
#define END_CODE 185

#endif /* CODE_H */
Loading

0 comments on commit 5732da8

Please sign in to comment.