static void set_fileselc(void *data, int nr) { EDITINFO *einf = (EDITINFO *) data; Char *c=NULL, *h, *s; nr = perm[nr]; if ((nr==OUTPUTBUTTON || nr>=NR_BUTTON) && einf->outputname) { h = einf->outputname; s = strip_name(einf->outputname); if (s!=h) { c=s-1; *c='\0'; } else h=NULL; } else { h = einf->pathname; s = strip_name(einf->pathname); if (s!=h) { c=s-1; *c='\0'; } else h=NULL; } fileselc_open(handle_fileselc_func[nr], data, translate(textremark[nr].lines), h, translate(textremark[nr].extension), s, einf->win_id); if (c) *c='/'; }
static void edit_auto_save(void *data, int dump) { EDITINFO *einf = (EDITINFO *) data; FILE *f; /* Using dump%s to keep a possible #%s# as extra backup */ if (!einf->auto_saved && !einf->empty) { if (dump) { buffer[0]=0; Ustrcat(buffer, translate("dump")); Ustrcat(buffer, strip_name(einf->filename)); Ustrcat(buffer, translate(EXTENSION)); } else { buffer[0]=0; Ustrcat(buffer, translate("#")); Ustrcat(buffer, strip_name(einf->filename)); Ustrcat(buffer, translate("#" EXTENSION)); } f = open_dirfile(userdir, buffer, "wb"); if (f) { set_file(f); put_filecode(DOCUMENTFILE); save_editwindow(einf->info); unset_file(); cleanup_stencilstack(); fclose(f); einf->auto_saved = MP_True; } else failure=MP_True; } /* ** In case of a failure, the document should be saved ** in another file, to make sure nothing gets lost. ** */ }
void cramped_name(const char *s, char *t, int w) { const char *q=s; char *p=t, tus[256]; int l, d, h; l = strlen(q); d = l - w; if (d > 0) { strip_name(tus, s); q = tus; l = strlen(tus); d = l - w; } if (d <= 0) strcpy(t,s); else { if (w < 12) /* 8.3 */ strcpy(t, q+d); /* only the last ch's */ else { h = (w-3)/2; strncpy(p,q,h); p+=h; *p++='.'; *p++='.'; *p++='.'; strcpy(p,q+l-h); } } }
static void remove_auto_save(EDITINFO *einf) { buffer[0] = '\0'; Ustrcat(buffer, userdir); Ustrcat(buffer, translate("/#")); Ustrcat(buffer, strip_name(einf->filename)); Ustrcat(buffer, translate("#" EXTENSION)); remove_file(buffer); }
static void disp_short ( char *string, /* resultant string */ int kbshort, /* keyboard shortcut to be displayed */ int left /* left-justify and 0-terminate string if true */ ) { int i,j; /* counters */ i = 3; /* position of the leftmost character */ switch ( kbshort & 0xFF ) { case 0x08: /* Backspace */ string[i--] = 'S'; string[i--] = 'B'; break; case 0x09: /* Tab */ string[i--] = 'B'; string[i--] = 'A'; string[i--] = 'T'; break; case 0x20: /* Space */ string[i--] = 'P'; string[i--] = 'S'; break; case 0x7F: /* Delete */ string[i--] = 'L'; string[i--] = 'E'; string[i--] = 'D'; break; default: /* Other */ if ( kbshort ) string[i--] = (char)(kbshort & 0xFF); break; } if ( kbshort & XD_CTRL ) /* Preceded by ^ ? */ string[i--] = '^'; for ( j = i; j >= 0; j-- ) /* fill blanks to the left */ string[j] = ' '; if ( i >= 0 && left ) /* if needed- left justify, 0 terminate */ { string[4] = 0; strip_name( string, string ); } }
/* 初始化mudlib中的master */ void init_master() { char buf[512]; #ifdef LPC_TO_C lpc_object_t *compiled_version; #endif object_t *new_ob; if (!strip_name(MASTER_FILE, buf, sizeof buf)) error("Illegal master file name '%s'\n", MASTER_FILE); #ifdef LPC_TO_C compiled_version = (lpc_object_t *)lookup_object_hash(buf); /* cv是个lpc的obj */ #endif new_ob = load_object(buf, compiled_version); /* 将master load进来 */ if (new_ob == 0) { fprintf(stderr, "The master file %s was not loaded.\n", MASTER_FILE); exit(-1); } set_master(new_ob); /* 设置master对象 */ }
/* * Specify tval and sval (type and subtype of object) originally * by RAK, heavily modified by -Bernd- * * This function returns the k_idx of an object type, or zero if failed * * List up to 50 choices in three columns */ static int wiz_create_itemtype(void) { int i, num, max_num; int col, row; int tval; cptr tval_desc; char ch; int choice[60]; char buf[160]; /* Clear screen */ Term_clear(); /* Print all tval's and their descriptions */ for (num = 0; (num < 60) && tvals[num].tval; num++) { row = 2 + (num % 20); col = 30 * (num / 20); ch = listsym[num]; prt(format("[%c] %s", ch, tvals[num].desc), row, col); } /* We need to know the maximal possible tval_index */ max_num = num; /* Choose! */ if (!get_com("Get what type of object? ", &ch)) return (0); /* Analyze choice */ for (num = 0; num < max_num; num++) { if (listsym[num] == ch) break; } /* Bail out if choice is illegal */ if (num >= max_num) return (0); /* Base object type chosen, fill in tval */ tval = tvals[num].tval; tval_desc = tvals[num].desc; /*** And now we go for k_idx ***/ /* Clear screen */ Term_clear(); /* We have to search the whole itemlist. */ for (num = 0, i = 1; (num < 60) && (i < max_k_idx); i++) { object_kind *k_ptr = &k_info[i]; /* Analyze matching items */ if (k_ptr->tval == tval) { /* Prepare it */ row = 2 + (num % 20); col = 30 * (num / 20); ch = listsym[num]; /* Acquire the "name" of object "i" */ strip_name(buf, i); /* Print it */ prt(format("[%c] %s", ch, buf), row, col); /* Remember the object index */ choice[num++] = i; } } /* We need to know the maximal possible remembered object_index */ max_num = num; /* Choose! */ if (!get_com(format("What Kind of %s? ", tval_desc), &ch)) return (0); /* Analyze choice */ for (num = 0; num < max_num; num++) { if (listsym[num] == ch) break; } /* Bail out if choice is "illegal" */ if (num >= max_num) return (0); /* And return successful */ return (choice[num]); }
/* * Get an object kind for creation (or zero) * * List up to 60 choices in three columns */ static int wiz_create_itemtype(void) { int i, num, max_num; int col, row; int tval; cptr tval_desc; char ch; int choice[60]; static const char choice_name[] = ("abcdefghijklmnopqrst" "ABCDEFGHIJKLMNOPQRST" "0123456789:;<=>?@%&*"); const char *cp; char buf[160]; /* Clear screen */ Term_clear(); /* Print all tval's and their descriptions */ for (num = 0; (num < 60) && object_group_tval[num]; num++) { row = 2 + (num % 20); col = 30 * (num / 20); ch = choice_name[num]; prt(format("[%c] %s", ch, object_group_text[num]), row, col); } /* We need to know the maximal possible tval_index */ max_num = num; /* Choose! */ if (!get_com("Get what type of object? ", &ch)) return (0); /* Analyze choice */ num = -1; if ((cp = strchr(choice_name, ch)) != NULL) num = cp - choice_name; /* Bail out if choice is illegal */ if ((num < 0) || (num >= max_num)) return (0); /* Base object type chosen, fill in tval */ tval = object_group_tval[num]; tval_desc = object_group_text[num]; /*** And now we go for k_idx ***/ /* Clear screen */ Term_clear(); /* We have to search the whole itemlist. */ for (num = 0, i = 1; (num < 60) && (i < z_info->k_max); i++) { object_kind *k_ptr = &k_info[i]; /* Analyze matching items */ if (k_ptr->tval == tval) { /* Hack -- Skip instant artifacts */ if (k_ptr->flags3 & (TR3_INSTA_ART)) continue; /* Prepare it */ row = 2 + (num % 20); col = 30 * (num / 20); ch = choice_name[num]; /* Get the "name" of object "i" */ strip_name(buf, i); /* Print it */ prt(format("[%c] %s", ch, buf), row, col); /* Remember the object index */ choice[num++] = i; } } /* Me need to know the maximal possible remembered object_index */ max_num = num; /* Choose! */ if (!get_com(format("What Kind of %s? ", tval_desc), &ch)) return (0); /* Analyze choice */ num = -1; if ((cp = strchr(choice_name, ch)) != NULL) num = cp - choice_name; /* Bail out if choice is "illegal" */ if ((num < 0) || (num >= max_num)) return (0); /* And return successful */ return (choice[num]); }
static void setpreferences(void) { int button; int oldbutton; /* DjV 039 090203 aux for arrow_form_do */ /* DjV 019 060103 070103 ---vvv--- */ static XDINFO prefinfo; static int menui=MFIRST;/* .rsc index of currently displayed menu item */ int mi; /* menui - MFIRST */ int redraw; /* true if to redraw menu item and key def */ int lm; /* length of text field in current menu item */ int lf; /* length of form for menu item text */ int i; /* counters */ int tmp[NITEM+2]; /* temporary kbd shortcuts (until OK) */ char aux[5]; /* temp. buffer for string manipulation */ /* DjV 019 060103 070103 ---^^^--- */ xd_set_rbutton(setprefs, OPTPAR2, (options.cprefs & DIALPOS_MODE) ? DMOUSE : DCENTER); xd_set_rbutton(setprefs, OPTPAR1, DNORMAL + options.dial_mode); itoa(options.tabsize, tabsize, 10); /* itoa(options.bufsize, copybuffer, 10); DjV 016 050103 moved to another dialog*/ /* DjV 019 060103 ---vvv--- */ /* button = xd_dialog(setprefs, TABSIZE); */ /* Get length of space for displaying menu items */ lf = setprefs[OPTMTEXT].ob_spec.tedinfo->te_txtlen - 1; /* Copy shortcuts to a temporary buffer (until OK'd) */ for ( i = 0; i <= NITEM; i++ ) tmp[i] = options.V2_2.kbshort[i]; /* Open dialog; then loop until OK or Cancel */ xd_open(setprefs, &prefinfo); redraw = TRUE; button = OPTMNEXT; /* anything*/ oldbutton = -1; /* DjV 039 090203 */ while ( button != OPTOK && button != OPTCANC ) { /* Display text of current menu item */ mi = menui - MFIRST; if ( redraw ) { lm = strlen(menu[menui].ob_spec.free_string); /* How long? Assumed always to be lm > 5 */ /* Copy menu text to dialog, remove shortcut text */ strncpy ( setprefs[OPTMTEXT].ob_spec.tedinfo->te_ptext, menu[menui].ob_spec.free_string, min(lm, lf) ); for ( i= min(lf, lm - 5); i < lf; i++ ) setprefs[OPTMTEXT].ob_spec.tedinfo->te_ptext[i] = ' '; /* Display defined shortcut */ disp_short( setprefs[OPTKKEY].ob_spec.tedinfo->te_ptext, tmp[mi], TRUE ); xd_draw ( &prefinfo, OPTMTEXT, 1 ); xd_draw ( &prefinfo, OPTKKEY, 1 ); redraw = FALSE; } /* HR Do not use goto's!!! */ do /* again: */ { /* xd_change( &prefinfo, button, NORMAL, TRUE ); DjV 039 090203 */ /* button = xd_form_do ( &prefinfo, ROOT ); DjV 039 090203 */ button = arrow_form_do ( &prefinfo, &oldbutton ); /* DjV 039 090203 */ /* Interpret shortcut from the dialog */ strip_name( aux, setprefs[OPTKKEY].ob_spec.tedinfo->te_ptext ); /* strupr ( aux ); DjV 019 280103 not needed anymore */ strcpy ( setprefs[OPTKKEY].ob_spec.tedinfo->te_ptext, aux ); i = strlen( aux ); tmp[mi] = 0; switch ( i ) { case 0: /* nothing defined */ break; case 1: /* single-character shortcut */ tmp[mi] = (int)aux[0]; break; case 2: /* two-character ^something shortcut */ if ( aux[0] == '^' && aux[1] >= 'A' /* DjV 019 280103 changed > 0x20 to >= 'A' */ && aux[1] <= 'Z' ) /* DjV 019 280103 changed > 0x7f fo <= 'Z' */ tmp[mi] = (int)aux[1] | XD_CTRL; else /* DjV 019 280103 */ tmp[mi] = XD_CTRL; /* DjV 019 280103 illegal */ break; default: /* longer shortcuts */ if ( aux[0] == '^' ) { tmp[mi] = XD_CTRL; aux[0] = ' '; strip_name( aux, aux ); } if ( strcmp( aux, "BS" ) == 0 ) tmp[mi] |= BACKSPC; /* DjV 019 280103 used macros instad of hex values*/ else if ( strcmp( aux, "TAB" ) == 0 ) tmp[mi] |= TAB; /* DjV 019 280103 */ else if ( strcmp( aux, "SP" ) == 0 ) tmp[mi] |= SPACE; /* DjV 019 280103 */ else if ( strcmp( aux, "DEL" ) == 0 ) tmp[mi] |= DELETE; /* DjV 019 280103 */ else tmp[mi] = XD_SCANCODE; /* use this to mark invalid */ break; } } while (check_key(button, tmp)); /* * Only menu items which lie between MFIRST and MLAST are considered; * if menu structure is changed, this interval should be redefined too; * only those menu items with a space in the second char position * are considered; other items are assumed not to be valid menu texts * note: below will crash in the (ridiculous) situation when the * first or the last menu item is not a good text */ switch ( button ) { case OPTMPREV: while ( menui > MFIRST && menu[--menui].ob_type != G_STRING); if ( menu[menui].ob_spec.free_string[1] != ' ' ) menui--; redraw = TRUE; break; case OPTMNEXT: while ( menui < MLAST && menu[++menui].ob_type != G_STRING); if ( menu[menui].ob_spec.free_string[1] != ' ' ) menui++; redraw = TRUE; break; case OPTKCLR: for ( i = 0; i <= NITEM; i++ ) tmp[i] = 0; redraw = TRUE; break; default: break; } } /* while... */ xd_close(&prefinfo); /* DjV 019 060103 ---^^^--- */ if (button == OPTOK) { int posmode = XD_CENTERED; /* DjV 019 070103 ---vvv--- */ /* Reset pressed OK button */ xd_change( &prefinfo, OPTOK, NORMAL, FALSE ); /* Move shortcuts into perm. storage and menu and display them */ for ( i = 0; i <= NITEM; i++ ) options.V2_2.kbshort[i] = tmp[i]; ins_shorts(); /* DjV 019 070103 ---^^^--- */ if (xd_get_rbutton(setprefs, OPTPAR2) == DMOUSE) { /* prefs |= DIALPOS_MODE; DjV 016 090103 */ options.cprefs |= DIALPOS_MODE; posmode = XD_MOUSE; } else options.cprefs &= ~DIALPOS_MODE; options.dial_mode = xd_get_rbutton(setprefs, OPTPAR1) - DNORMAL; /* DjV 016 050103 ---vvv--- */ /* moved to copyoptions if ((options.bufsize = atoi(copybuffer)) < 1) options.bufsize = 1; */ /* DjV 016 050103 ---^^^--- */ if ((options.tabsize = atoi(tabsize)) < 1) options.tabsize = 1; set_dialmode(); xd_setposmode(posmode); } /* DjV 019 070103 ---vvv--- */ else xd_change( &prefinfo, OPTCANC, NORMAL, FALSE ); /* DjV 019 070103 ---^^^--- */ }
static int set_name(void *data, Char *pathname) { EDITINFO *einf = (EDITINFO *) data; XTextProperty prop_name; Char *name; int namesize; Char *stripname, *nname; if (pathname == NULL) { EDITINFO *tinf; FlexArray istck; int i=0,j; int_init(istck); while (aig(tinf=(EDITINFO*)next_data_with_type(MAINEDITWINDOW, &i))) { if (!Ustrncmp(translate(EMPTYFILE),tinf->filename, Ustrlen(translate(EMPTYFILE)))) { j = Ustrtol(tinf->filename+Ustrlen(translate(EMPTYFILE)), NULL, 10); int_add(istck, j); } i++; } i=1; while (int_contains(istck,i)) i++; int_clear(istck); nname = (Char *) malloc(sizeof(Char)*(Ustrlen(userdir) + Ustrlen(translate("/" EMPTYFILE)) + 5 +Ustrlen(translate(EXTENSION)))); concat_in(nname, userdir, translate("/" EMPTYFILE)); stripname = nname + Ustrlen(nname); { Char sb[40]; Char *s; sb[39]=0; s=Ultostr(i,sb+39); Ustrcat(stripname,s); } Ustrcat(stripname, translate(EXTENSION)); } else nname = pathname; stripname = concat(strip_name(nname),NULL); if (!Ustrcmp(stripname+Ustrlen(stripname)-Ustrlen(translate(EXTENSION)), translate(EXTENSION))) stripname[Ustrlen(stripname)-Ustrlen(translate(EXTENSION))] = 0; namesize = Ustrlen(translate(EDITNAME)) + Ustrlen(stripname) + 1 + (einf->saved ? 0 : Ustrlen(translate(CHANGED))) + (einf->view_mode && !einf->shell ? Ustrlen(translate(VIEWCOM)) : 0) + (einf->shell && !einf->fini ? Ustrlen(translate(RUNCOM)) : 0) + (einf->shell && einf->fini ? Ustrlen(translate(DONECOM)) : 0); name = (Char *) malloc((size_t) namesize*sizeof(Char) ); if (name) { name[0]= '\0'; Ustrcat(name, translate(EDITNAME)); Ustrcat(name, stripname); if (!einf->saved && !einf->shell) Ustrcat(name, translate(CHANGED)); if (einf->view_mode && !einf->shell) Ustrcat(name, translate(VIEWCOM)); if (einf->shell && !einf->fini) Ustrcat(name, translate(RUNCOM)); if (einf->shell && einf->fini) Ustrcat(name, translate(DONECOM)); } { char *n; n= (char*)UstrtoLocale(name); if (!name || !XStringListToTextProperty(&n, 1, &prop_name)) { message(MP_ERROR, translate("No location for editname.")); return 0; } } XSetWMName(display, einf->win_id, &prop_name); free(einf->headername); if (einf->pathname!=nname) free(einf->pathname); free(einf->filename); einf->headername = name; einf->filename = stripname; einf->pathname = nname; { char *icn; icn = (char*)UstrtoLocale(stripname); if (!XStringListToTextProperty(&icn, 1, &prop_name)) { message(MP_ERROR, translate("No location for editicon.")); return 0; } } XSetWMIconName(display, einf->win_id, &prop_name); return 1; }
static int do_cmd_squelch_aux(void) { int i, j, temp, num, max_num; int col, row; int typeval; cptr tval_desc; char ch, sq; int choice[60]; char buf[160]; byte color; /* Clear screen */ Term_clear(); /* * Print all typeval's and their descriptions * * This uses the above arrays. I combined a few of the * tvals into single typevals. */ for (num = 0; (num<60) && typevals[num].tval; num++) { row = 3 + (num % 20); col = 30 * (num / 20); ch = head[num/26] +num%26; prt(format("[%c] %s", ch, typevals[num].desc), row, col); } /* We need to know the maximal possible tval_index */ max_num = num; /* Choose! */ if (!get_com("Squelch what type of object? (Q: Secondary Menu for Weapons and Armour) ", &ch)) return (0); if (ch=='Q') { /* Switch to secondary squelching menu */ do_qual_squelch(); } else { /* Analyze choice */ num = ch-'a'; /* Bail out if choice is illegal */ if ((num < 0) || (num >= max_num)) return (0); /* Base object type chosen, fill in tval */ typeval = typevals[num].tval; tval_desc = typevals[num].desc; /*** And now we go for k_idx ***/ /* Clear screen */ while (1) { Term_clear(); /* First sort based on value */ /* Step 1: Read into choice array */ for (num = 0, i = 1; (num < 60) && (i < MAX_K_IDX); i++) { object_kind *k_ptr = &k_info[i]; if (tv_to_type[k_ptr->tval] == typeval) { if (k_ptr->flags3 & (TR3_INSTA_ART)) continue; if (!(k_ptr->aware)) continue; choice[num++] = i; } } max_num = num; /* Step 2: Simple bubble sort */ for (i=0; i<max_num; i++) { for (j=i; j<max_num; j++) { if ((k_info[choice[i]].tval>k_info[choice[j]].tval) || ((k_info[choice[i]].tval==k_info[choice[j]].tval) && (k_info[choice[i]].cost>k_info[choice[j]].cost))) { temp = choice[i]; choice[i] = choice[j]; choice[j] = temp; } } } if (!max_num) c_put_str(TERM_RED, "No known objects of this type.", 3, 0); else { for (num = 0; num<max_num; num++) { object_kind *k_ptr = &k_info[choice[num]]; /* Prepare it */ row = 3 + (num % 20); col = 30 * (num / 20); ch = head[num/26] + (num%26); /* Acquire the "name" of object "i" */ strip_name(buf, choice[num]); /* Get the squelch character */ sq = (k_ptr->squelch ? '*' : ' '); /* Get the color */ color = (k_ptr->squelch ? TERM_RED : TERM_L_GREEN); /* Print it */ prt(format("[%c%c] ", ch, sq), row, col); c_put_str(color, buf, row, col+5); } /* Print the legend */ prt("'*': Squelch ' ': Do not squelch", 1, 0); } /* Choose! */ if (!get_com(format("%s : Command? (^A: Squelch all ^U: Unsquelch all)", tval_desc), &ch)) return (1); if (ch==KTRL('A')) { /* ^A --> Squelch all items */ for (i=0; i<max_num; i++) { k_info[choice[i]].squelch = TRUE; } } else if (ch==KTRL('U')) { /* ^U --> Unsquelch all items */ for (i=0; i<max_num; i++) { k_info[choice[i]].squelch = FALSE; } } else { /* Analyze choice */ num = -1; if ((ch >= head[0]) && (ch < head[0] + 26)) num = ch - head[0]; if ((ch >= head[1]) && (ch < head[1] + 26)) num = ch - head[1] + 26; if ((ch >= head[2]) && (ch < head[2] + 17)) num = ch - head[2] + 52; /* Bail out if choice is "illegal" */ if ((num < 0) || (num >= max_num)) return (1); /* Toggle */ k_info[choice[num]].squelch = (k_info[choice[num]].squelch ? FALSE : TRUE); } } } /* And return successful */ return (1); }