int main(int argc, char **argv) { char *s; #if 0 /* Shouldn't need this.. */ signal(SIGHUP, SIG_IGN); #endif /* initialize locale support */ setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); init_env(); do_args(argc, argv); memset(inbuf, 0, sizeof(inbuf)); if (argc > 2) { strncpy(logfname, argv[2], sizeof(logfname)); if (argc > 3) strncpy(homedir, argv[3], sizeof(homedir)); else if ((s = getenv("HOME")) != NULL) strncpy(homedir, s, sizeof(homedir)); else homedir[0] = 0; } else logfname[0] = 0; return execscript(argv[1]) != OK; }
// Banner and copyright notice // void displayBanner(void) { // Wait for the serial port, if required while(!Serial); // print the banner and copyright notice // please note the license requires that you maintain this notice execscript(SCRIPT_PROGMEM, (numvar) (builtin_table + strlen(builtin_table)+1), 0); }
///////// // // Call a Bitlash script function and push its return value on the stack // void callscriptfunction(byte scripttype, numvar scriptaddress) { // note on function name management // // we get here with the name of the function we want to call in global idbuf. // parsearglist() pushes a copy of idbuf into the string pool, so // the function's name is the first data in the string pool slab // that will be deallocated when the function returns // // we can refer to this copy of the function's name via the callername macro // parsearglist(); numvar ret = execscript(scripttype, scriptaddress, calleename); releaseargblock(); vpush(ret); }
/* * Call another script! */ int docall(char *text) { struct line *oldline; struct env *oldenv; int er; if (*text == 0) syntaxerr(_("(argument expected)")); if (inexpect) { fprintf(stderr, _("script \"%s\" line %d: call inside expect%s\n"), curenv->scriptname, thisline->lineno, "\r"); exit(1); } oldline = thisline; oldenv = curenv; if ((er = execscript(text)) != 0) exit(er); /* freemem(); */ thisline = oldline; curenv = oldenv; return 0; }
////////// // // runBackgroundTasks // // Runs one eligible background task per invocation // Returns true if a task was run // void runBackgroundTasks(void) { byte i; #ifdef suspendBackground if (suspendBackground) return; #endif for (i=0; i<NUMTASKS; i++) { // run one task per call on a round robin basis if (++curtask >= NUMTASKS) curtask = 0; if ((tasklist[curtask] != SLOT_FREE) && (((signed long) millis() - (signed long) waketime[curtask])) >= 0) { // run it with the background flag set background = 1; execscript(SCRIPT_EEPROM, findend(tasklist[curtask]), 0); // schedule the next time quantum for this task waketime[curtask] = millis() + snoozetime[curtask]; background = 0; break; } } }
///////// // // doCommand: main entry point to execute a bitlash command // numvar doCommand(char *cmd) { return execscript(SCRIPT_RAM, (numvar) cmd, 0); }
int main(int argc, char* argv[]) { initscr(); scrollok(stdscr, TRUE); wprintw(stdscr, "Welcome to Scripted ver. %d.%d for the Brave Quest engine.\nCopyright 2012 Mad Science Inc.\nPlease do not redistrubute.\n",scriptedvernum,scriptedvernum2); stufffilename(); if(loadscript(filename) == 1) { wprintw(stdscr, "File not Found. Would you like to make a new file?\n"); if(bie() == 'y') { cleanfilebuff(); if(savescript(filename) == 1) { wprintw(stdscr, "Your disk sucks.\n"); bi(); return 1; } } else { wprintw(stdscr, "Goodbye.\n"); endwin(); return 1; } } currlinenum = linenum; menu(); wprintw(stdscr, "Press escape to go to the save menu\n"); for(;;) { wprintw(stdscr, "q= give, w= take, e= say, r= flag, t= move, y= battle, u= check flag, i= check item, o= party add, p= party remove, [ = check character\n"); wprintw(stdscr, "a= warp, s= check experience, d= give experience, f= make experience, g= exec script, h= screen effect, j= user input, k= goline, l= make health\n"); wprintw(stdscr, "b= check stat, n= make stat, m= blank, ,= show line, .= change line.\n"); input[0] = bie(); if(input[0] == 27) menu(); if(input[0] == 'q') give(); if(input[0] == 'w') take(); if(input[0] == 'e') say(); if(input[0] == 'r') flag(); if(input[0] == 't') mmove(); if(input[0] == 'y') battle(); if(input[0] == 'u') checkflag(); if(input[0] == 'i') checkitem(); if(input[0] == 'o') partyadd(); if(input[0] == 'p') partyrm(); if(input[0] == '[') checkparty(); if(input[0] == 'a') warp(); if(input[0] == 's') checkexp(); if(input[0] == 'd') giveexp(); if(input[0] == 'f') makeexp(); if(input[0] == 'g') execscript(); if(input[0] == 'h') screeneffect(); if(input[0] == 'j') userinput(); if(input[0] == 'k') goline(); if(input[0] == 'l') makehealth(); if(input[0] == 'z') teachspell(); if(input[0] == 'x') unlearnspell(); if(input[0] == 'b') checkstat(); if(input[0] == 'n') makestat(); if(input[0] == 'm') blank(); if(input[0] == ',') showline(); if(input[0] == '.') changeline(); if(currlinenum > linenum) linenum = currlinenum; } return 0; };
/*main loop, message sender, etc.pp.*/ int main(int argc,char**argv) { int c,optindex=1; struct dhcp_msg *msg; /*parse options*/ argv0=*argv; while(1){ c=getopt_long(argc,argv,shortopt,longopt,&optindex); if(c==-1)break; switch(c){ case 'p':getprefix=1;break; case 'P':getprefix=0;break; case 'a':getaddress=1;break; case 'A':getaddress=0;break; case 'd':getdns=1;break; case 'D':getdns=0;break; case 'r':retries=atoi(optarg);break; case 'l':localid=optarg;break; case 'u':setduid(optarg);break; case 'c':userapid=1;break; case 'C':userapid=0;break; case 'L':setloglevel(optarg);break; default: fprintf(stderr,"Syntax error in arguments.\n"); printhelp(); return 1; break; case 'h': printhelp(); return 0; break; } } if((optind+2)!=argc){ fprintf(stderr,"Syntax error.\n"); printhelp(); return 1; } device=argv[optind]; script=argv[optind+1]; if(DUIDLEN==0){ if(localid) setlocalid(localid); else initlocalid(); } /*init socket*/ initsocket(DHCP_CLIENTPORT,device); if(sockfd<0){ td_log(LOGERROR,"unable to allocate socket, exiting."); exit(1); } /*init my own stuff*/ inititems(); /*init SOLICIT/IREQ msg*/ if(!getaddress && !getprefix){ msg=newmessage(MSG_IREQUEST); addrecvfilter(MSG_REPLY); }else{ msg=newmessage(MSG_SOLICIT); addrecvfilter(MSG_ADVERTISE); } COMPAREMSGID=1; settargetserver(&msg->msg_peer); messageaddopt(msg,OPT_CLIENTID); if(getdns){ messageaddoptrequest(msg,OPT_DNS_SERVER); messageaddoptrequest(msg,OPT_DNS_NAME); } if(getaddress)messageaddopt(msg,OPT_IANA); if(getprefix)messageaddopt(msg,OPT_IAPD); if(userapid&&(getaddress||getprefix))messageaddopt(msg,OPT_RAPIDCOMMIT); /*start main loop*/ for(c=0;c<retries;c++){ sendmessage(msg); fd_set rfd,xfd; struct timeval tv; int sret; //wait for event FD_ZERO(&rfd); FD_ZERO(&xfd); FD_SET(sockfd,&rfd); FD_SET(sockfd,&xfd); tv.tv_sec=1; tv.tv_usec=0; sret=select(sockfd+1,&rfd,0,&xfd,&tv); //check for errors if(sret<0){ int e=errno; if(e==EAGAIN)continue; td_log(LOGERROR,"Error caught: %s\n",strerror(e)); return 1; } //check for event if(sret>0){ if(FD_ISSET(sockfd,&rfd)){ struct dhcp_msg*msg2; msg2=readmessage(); if(msg2) if(handlemessage(msg2,msg)==0)break; } if(FD_ISSET(sockfd,&xfd)){ td_log(LOGERROR,"Exception on socket caught.\n"); return 1; } }else td_log(LOGDEBUG,"timeout, iteration %i",c); } /*execute script*/ return execscript(); }