bool parse_tintin_command(char *command, char *arg) { /* this lines almost totally rewrote to put all command functions into a struct array. Size of array defined in tintin.h; Array itself defined in cmds.h. Struct: char alias - with it you can easily add aliases with same function name void function_name - main stuff char hlpfile - this field is for help_command. do not forget to link aliases to one help file. would rely it would not crash... En. */ CharLower(command); if(isdigit(*command)) { int a1=0; int a2=0; sscanf(command,"%d:%d",&a1,&a2); get_arg_in_braces(arg, arg, WITH_SPACES); do_cycle( 1, a1, 1, a2, arg ); /* do_cycle( bound1, bound2, step, delay, command); */ return false; } if(*command == cCommandChar) return false; for(int i=0;i<JMC_CMDS_NUM;i++) if((command[0]==jmc_cmds[i].alias[0]) &&(is_abrev(command,jmc_cmds[i].alias))) { (*(jmc_cmds[i].jmcfn))(arg); return true; } tintin_puts2(rs::rs(1145)); return false; }
void help_command(const char *arg, struct session *ses) { FILE *myfile=NULL; char text[BUFFER_SIZE], line[BUFFER_SIZE], filestring[BUFFER_SIZE]; if (strcmp(DEFAULT_FILE_DIR, "HOME")) { sprintf(filestring, "%s/KBtin_help", DEFAULT_FILE_DIR); myfile = check_file(filestring); } #ifdef DATA_PATH if (!myfile) { sprintf(filestring, "%s/KBtin_help", DATA_PATH); myfile = check_file(filestring); } #endif if (!myfile) { sprintf(filestring, "%s_help", tintin_exec); myfile = check_file(filestring); } if (!myfile) { sprintf(filestring, "%s/KBtin_help", getenv("HOME")); myfile = check_file(filestring); } if (!myfile) { tintin_eprintf(0, "#Help file not found - no help available."); tintin_eprintf(0, "#Locations checked:"); if (strcmp(DEFAULT_FILE_DIR, "HOME")) tintin_eprintf(0, "# %s/KBtin_help%s", DEFAULT_FILE_DIR, COMPRESSION_EXT); #ifdef DATA_PATH tintin_eprintf(0, "# %s/KBtin_help%s", DATA_PATH, COMPRESSION_EXT); #endif tintin_eprintf(0, "# %s_help%s", tintin_exec, COMPRESSION_EXT); tintin_eprintf(0, "# %s/KBtin_help%s", getenv("HOME"), COMPRESSION_EXT); return; } if (*arg==tintin_char) arg++; if (*arg) { sprintf(text, "~%s", arg); while (fgets(line, sizeof(line), myfile)) { if (*line == '~') { if (*(line + 1) == '*') break; if (is_abrev(text, line)) { while (fgets(line, sizeof(line), myfile)) { if ((*line == '~')&&(*(line+1)=='~')) goto end; else { *(line + strlen(line) - 1) = '\0'; if (*line!='~') tintin_printf(0, "%s", line); } } } } } } else { while (fgets(line, sizeof(line), myfile)) { if ((*line == '~')&&(*(line+1)=='~')) goto end; else { *(line + strlen(line) - 1) = '\0'; if (*line!='~') tintin_printf(0, "%s", line); } } } tintin_printf(0, "#Sorry, no help on that word."); end: fclose(myfile); }
void parse_input(char *input) { char command[BUFFER_SIZE], arg[BUFFER_SIZE], result[BUFFER_SIZE]; char *input2; bPasswordEcho = TRUE; if(*input=='\0') { write_line_mud(""); return ; } if ( verbatim && *input == cCommandChar && *(input+1) == 'v' ) {// check verbatim command char command[BUFFER_SIZE]; char* input2=get_arg_stop_spaces(input+1, command); if(command[0] == 'v' && is_abrev(command, "verbatim")){ char arg[BUFFER_SIZE]; get_arg_all(input2, arg); verbatim_command(arg); return; } } if (verbatim ) { write_line_mud(input); return ; } if (*input==verbatim_char) { input++; write_line_mud(input); return ; } substitute_myvars(input, result); input2=result; while(*input2) { //* en:colon // if(*input2==';') if(*input2==cCommandDelimiter||(bColon && *input2==';')&&*(input2-1)!='\\') input2++; //*/en input2=get_arg_stop_spaces(input2, command); input2=get_arg_all(input2, arg); //* en:prefix if(s_prefix[0] && command[0] != cCommandChar) { char p_command[BUFFER_SIZE]; strcpy(p_command,command); strcat(p_command," "); strcat(p_command,arg); strcpy(command,s_prefix); strcpy(arg,p_command); } //*/en if(*command==cCommandChar) { if (bDisplayCommands) { // output command in square brackets char strInputCommand[BUFFER_SIZE], strOutputBuffer[BUFFER_SIZE]; strcpy(strInputCommand, "\n["); strcat(strInputCommand, command); if (*arg != '\0') { strcat(strInputCommand, " "); strcat(strInputCommand, arg); } strcat(strInputCommand, "]"); add_codes(strInputCommand, strOutputBuffer, "brown", TRUE); tintin_puts2(strOutputBuffer); if (hLogFile.is_open()) { log(strInputCommand); } } parse_tintin_command(command+1, arg); } //* en:comments else if(*command==cCommentChar); //*/en else { //* en:waits if(iWaitState>0) { char *ptr1,*ptr2; for(ptr1=mQueue;*ptr1&&*ptr1!='\0';ptr1++); *ptr1++=cCommandDelimiter; for(ptr2=command;*ptr2&&*ptr2!='\0';ptr2++,ptr1++) *ptr1=*ptr2; if(*arg) *ptr1++=' '; for(ptr2=arg;*ptr2&&*ptr2!='\0';ptr2++,ptr1++) *ptr1=*ptr2; *ptr1++='\0'; continue; } //* en ALIAS_INDEX ind; if( (ind=AliasList.find(command)) != AliasList.end() && ind->second->m_pGroup->m_bEnabled ) { int i; char *cpsource, *cpsource2, newcommand[BUFFER_SIZE], end; strcpy(vars[0], arg); for(i=1, cpsource=arg; i<10; i++) { /* Next lines CHANGED to allow argument grouping with aliases */ while (*cpsource == ' ') cpsource++; end = (*cpsource == '{') ? '}' : ' '; cpsource = (*cpsource == '{') ? cpsource+1 : cpsource; for(cpsource2=cpsource; *cpsource2 && *cpsource2!=end; cpsource2++); strncpy(vars[i], cpsource, cpsource2-cpsource); *(vars[i]+(cpsource2-cpsource))='\0'; cpsource=(*cpsource2) ? cpsource2+1 : cpsource2; } ALIAS* pal = ind->second; prepare_actionalias((char*)pal->m_strRight.data(), newcommand); if(!strcmp(pal->m_strRight.data(), newcommand) && *arg) { strcat(newcommand, " "); strcat(newcommand, arg); } parse_input(newcommand); } else if(speedwalk && !*arg && is_speedwalk_dirs(command)) do_speedwalk(command); else { get_arg_with_spaces(arg,arg); write_com_arg_mud(command, arg); } } } return; }
void dogoto_command(const char *arg, struct session *ses) { char A[BUFFER_SIZE], B[BUFFER_SIZE], distvar[BUFFER_SIZE], locvar[BUFFER_SIZE], pathvar[BUFFER_SIZE]; char left[BUFFER_SIZE], right[BUFFER_SIZE], tmp[BUFFER_SIZE], cond[BUFFER_SIZE]; int a, b, i, j, s; int d[MAX_LOCATIONS], ok[MAX_LOCATIONS], way[MAX_LOCATIONS]; char path[BUFFER_SIZE], *pptr; arg=get_arg(arg, A, 0, ses); arg=get_arg(arg, B, 0, ses); arg=get_arg(arg, distvar, 0, ses); arg=get_arg(arg, locvar, 0, ses); arg=get_arg(arg, pathvar, 0, ses); if ((!*A)||(!*B)) { tintin_eprintf(ses, "#SYNTAX: #dogoto <from> <to> [<distvar> [<locvar> [<pathvar>]]] [#else ...]"); return; } bool flag=*distvar||*locvar||*pathvar; for (a=0;a<MAX_LOCATIONS;a++) if (ses->locations[a]&&!strcmp(ses->locations[a], A)) break; if (a==MAX_LOCATIONS) goto not_found; for (b=0;b<MAX_LOCATIONS;b++) if (ses->locations[b]&&!strcmp(ses->locations[b], B)) break; if (b==MAX_LOCATIONS) goto not_found; for (i=0;i<MAX_LOCATIONS;i++) { d[i]=INF; ok[i]=0; } d[a]=0; do { s=INF; for (j=0;j<MAX_LOCATIONS;j++) if (!ok[j]&&(d[j]<s)) s=d[i=j]; if (s==INF) goto not_found; ok[i]=1; for (struct routenode *r=ses->routes[i];r;r=r->next) if (d[r->dest]>s+r->distance) { if (!*(r->cond)) goto good; substitute_vars(r->cond, tmp); substitute_myvars(tmp, cond, ses); if (eval_expression(cond, ses)) { good: d[r->dest]=s+r->distance; way[r->dest]=i; } } } while (!ok[b]); sprintf(tmp, "%d", d[b]); if (*distvar) set_variable(distvar, tmp, ses); j=0; for (i=b;i!=a;i=way[i]) d[j++]=i; d[j]=a; pptr=path; for (i=j;i>=0;i--) pptr+=snprintf(pptr, path-pptr+BUFFER_SIZE, " %s", ses->locations[d[i]]); pptr=path+(pptr!=path); if (*locvar) set_variable(locvar, pptr, ses); pptr=path; for (i=j;i>0;i--) { for (struct routenode *r=ses->routes[d[i]];r;r=r->next) if (r->dest==d[i-1]) { if (flag) pptr+=snprintf(pptr, path-pptr+BUFFER_SIZE, " {%s}", r->path); else { tintin_printf(ses, "%-10s>%-10s {%s}", ses->locations[d[i]], ses->locations[d[i-1]], r->path); } } } pptr=path+(pptr!=path); if (*pathvar) set_variable(pathvar, pptr, ses); return; not_found: arg=get_arg_in_braces(arg, left, 0); if (*left == tintin_char) { if (is_abrev(left + 1, "else")) { get_arg_in_braces(arg, right, 1); parse_input(right, true, ses); return; } if (is_abrev(left + 1, "elif")) { if_command(arg, ses); return; } } if (*left) tintin_eprintf(ses, "#ERROR: cruft after #dogoto: {%s}", left); if (!flag) tintin_printf(ses, "No paths from %s to %s found.", A, B); }