Commit 1e2615b6 authored by Andrew Price's avatar Andrew Price

Remove some unused mwscript bits

The purge begins.
parent de661592
......@@ -88,21 +88,6 @@ char ** makeargs(int argc, const char **argv, int offset)
return (new);
}
static char *debug_info(const char *filename, int lineno)
{
char buff[512];
snprintf(buff, 511, "%s:%d", filename, lineno);
return ( strdup(buff) );
}
static int endchar(const char *haystack, char needle)
{
int len;
len=strlen(haystack);
if (haystack[len-1] == needle) return (1);
else return(0);
}
/* autoexecs any new initialisation functions */
void RunInitFuncs(int talkinit)
{
......@@ -135,250 +120,6 @@ void RunInitFuncs(int talkinit)
}
}
FuncNames scrtc[]={
{"talkname" ,part_who_talk},
{"whoname" ,part_who},
{"username" ,part_user},
{"gag" ,gaglist_tc_filter},
{"bind" ,list_bind},
{"boardexec" ,list_commands},
{"exec" ,list_chat_commands},
{"script" ,list_script},
{"null" ,NULL},
{NULL ,NULL}
};
void LoadFunction(char *funcname, char *header, FILE *file, int *lineno, const char *filename, int flags)
{
struct function *new;
char *buff = NULL;
char *line = NULL;
const char *bits[MAX_ARGC];
int num;
struct label *label=NULL;
struct code *codeend=NULL, *newcode;
Instruction *inst;
/* new vars for tab-completion */
const char *argv[MAX_ARGC];
int argc;
int lp;
FuncNames *fn = NULL;
int found;
new=function_list;
while (new!=NULL && strcasecmp(funcname, new->name)) new=new->next;
if (new!=NULL)
{
printf("Function %s already exists. Redefined at line %d in %s.\n", funcname, *lineno, filename);
buff = NULL;
while (!feof(file))
{
if ((buff = frl_line_nspace(file, "#")) == NULL) break;
*lineno+=num_lines_read();
if (!strcasecmp(buff, "endfunc")) break;
free(buff);
buff = NULL;
}
if (buff) free(buff);
return;
}
/* insert new function into the list */
new=(struct function *)malloc(sizeof(struct function));
new->name=strdup(funcname);
new->new=true;
new->code=NULL;
new->jump=NULL;
new->flags = flags;
/* add current function to function list */
/* new ordered insert - so tab-completion for script names works */
{
struct function *prev, *cur;
cur = function_list;
prev = NULL;
while (cur!=NULL && strcmp(cur->name,new->name) < 0)
{
prev=cur;
cur=cur->next;
}
/* start of list */
if (prev == NULL)
{
new->next = function_list;
function_list = new;
}
/* end of list */
else if (cur == NULL)
{
prev->next = new;
new->next = NULL;
}
/* middle of list */
else
{
new->next = cur;
prev->next = new;
}
}
/* work out tab-completion status information */
new->numcomp = 0;
new->complist = NULL;
argc = ParseLine(header, argv);
if (argc <= 2)
{
new->numcomp = 1;
new->complist = malloc(sizeof(CompletionList));
new->complist[0].Command = "";
new->complist[0].Mode = 2;
new->complist[0].FArg = 1;
new->complist[0].LArg = -1;
new->complist[0].CPFunction = part_who;
}
else
{
for (lp=2; lp<argc; lp++)
{
/* go through tab complete list */
fn = scrtc;
found = 0;
while(fn->name)
{
if (!strcasecmp(fn->name, argv[lp]))
{
found = 1;
break;
}
fn++;
}
/* handle special 'ad infinitum' sequence */
if (!strcasecmp("...", argv[lp])) found = 2;
/* if not found, skip arguments */
if (!found)
{
printf("Invalid argument type '%s' for function %s, on line %d in %s\n", argv[lp], funcname, *lineno, filename);
break;
}
else
{
/* completion function */
new->numcomp++;
new->complist = realloc(new->complist, sizeof(CompletionList) * new->numcomp);
new->complist[new->numcomp - 1].Command = "";
new->complist[new->numcomp - 1].Mode = 2;
new->complist[new->numcomp - 1].FArg = lp-1;
new->complist[new->numcomp - 1].LArg = (found==2)?-1:lp-1;
new->complist[new->numcomp - 1].CPFunction = fn->function;
/* if ad infinitum, skip rest of arguments */
if (found == 2) break;
}
}
}
while (!feof(file) && (line = frl_line(file)))
{
(*lineno)++;
if (strchr("#\n\r", line[0])!=NULL) { free(line); continue; }
num=ParseLine(line, bits);
if (num==0) { free(line); continue; }
if (bits[0][0]=='#') { free(line); continue; }
if (!strcasecmp(bits[0], "endfunc")) break;
if (endchar(bits[0], ':'))
{
char *p;
if ((p=strrchr(bits[0],':'))!=NULL) *p=0;
label=new->jump;
while (label!=NULL && strcasecmp(bits[0], label->name))
label=label->next;
if (label!=NULL)
{
printf("Label %s referenced at %s:%d already in use at %s\n", label->name, filename, *lineno, label->debug);
label=NULL;
free(line);
continue;
}
label=(struct label *)malloc(sizeof(struct label));
label->name=strdup(bits[0]);
label->debug=debug_info(filename, *lineno);
label->next=new->jump;
label->where=NULL; /* fill in later */
new->jump=label;
}else
{
inst=inst_table;
while (inst->name != NULL && strcasecmp(inst->name, bits[0])) {
inst++;
}
if (inst->name==NULL)
{
printf("Invalid instruction '%s' at line %d of file %s\n", bits[0], *lineno, filename);
free(line);
continue;
}
newcode=(struct code *)malloc(sizeof(struct code));
newcode->inst=inst;
newcode->argc=num-1;
newcode->argv=makeargs(num, bits, 1);
newcode->debug=debug_info(filename, *lineno);
newcode->parent=new;
newcode->next=NULL;
if (new->code==NULL)
{
new->code=newcode;
codeend=newcode;
}else
{
codeend->next=newcode;
codeend=newcode;
}
/* fill in the labels */
if (label!=NULL)
{
label=new->jump;
while (label!=NULL) {
if (label->where==NULL)
label->where=newcode;
label=label->next;
}
label=NULL;
}
}
free(line);
}
if (line) free(line);
/* automatic return at the end of a function if theres a label hanging open. */
if (new->code!=NULL && label!=NULL) {
inst=inst_table;
while (inst->name != NULL && strcasecmp(inst->name, "return")) {
inst++;
}
newcode=(struct code *)malloc(sizeof(struct code));
newcode->inst=inst;
newcode->argc=0;
newcode->argv=NULL;
newcode->debug=debug_info(filename, *lineno);
newcode->parent=new;
newcode->next=NULL;
codeend->next=newcode;
label=new->jump;
while (label!=NULL) {
if (label->where==NULL)
label->where=newcode;
label=label->next;
}
label=NULL;
}
}
void DestroyFunction(const char *funcname)
{
struct function *func, *funcold;
......
......@@ -241,7 +241,6 @@ void CallFunction(struct code *code, int argc, char **argv);
int ExecInst(char *line);
void scr_devel_msg(struct code *pc, const char *fmt, ...) __attribute__((format(printf,2,3)));
void RunInitFuncs(int talkinit);
extern void LoadFunction(char *, char *, FILE *, int *, const char *, int);
int arg_count(var_list_t *list);
int var_isanum(var_op_t *op, int *result, int onlydecimal);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment