MCPcopy Index your code
hub / github.com/NetHack/NetHack / nhl_text

Function nhl_text

src/nhlua.c:809–851  ·  view source on GitHub ↗

text("foo\nbar\nbaz") */

Source from the content-addressed store, hash-verified

807
808/* text("foo\nbar\nbaz") */
809staticfn int
810nhl_text(lua_State *L)
811{
812 int argc = lua_gettop(L);
813
814 if (argc > 0) {
815 menu_item *picks = (menu_item *) 0;
816 winid tmpwin;
817
818 tmpwin = create_nhwindow(NHW_MENU);
819 start_menu(tmpwin, MENU_BEHAVE_STANDARD);
820
821 while (lua_gettop(L) > 0) {
822 char *ostr = dupstr(luaL_checkstring(L, 1));
823 char *ptr, *str = ostr;
824 char *lstr = str + strlen(str) - 1;
825
826 do {
827 char *nlp = strchr(str, '\n');
828
829 if (nlp && (nlp - str) <= 76) {
830 ptr = nlp;
831 } else {
832 ptr = str + 76;
833 if (ptr > lstr)
834 ptr = lstr;
835 }
836 while ((ptr > str) && !(*ptr == ' ' || *ptr == '\n'))
837 ptr--;
838 *ptr = '\0';
839 add_menu_str(tmpwin, str);
840 str = ptr + 1;
841 } while (*str && str <= lstr);
842 lua_pop(L, 1);
843 free(ostr);
844 }
845
846 end_menu(tmpwin, (char *) 0);
847 (void) select_menu(tmpwin, PICK_NONE, &picks);
848 destroy_nhwindow(tmpwin);
849 }
850 return 0;
851}
852
853/* makeplural("zorkmid") */
854staticfn int

Callers

nothing calls this directly

Calls 3

dupstrFunction · 0.85
add_menu_strFunction · 0.85
select_menuFunction · 0.85

Tested by

no test coverage detected