void op_quit(void) { if(automap_unexplore()) return; z_close(); /* puts("@quit\n"); */ glk_exit(); }
static void verb_quit(winid_t win) { glk_set_window(win); glk_put_string("Thanks for playing.\n"); glk_exit(); /* glk_exit() actually stops the process; it does not return. */ }
int main(int argc, char *argv[]) { glkunix_startup_t data; if(!sglk_init(argc, argv, &data)) return 1; glkunix_startup_code(&data); glk_main(); glk_exit(); return 0; }
void os_fatal (const char *s) { char err[256]; sprintf(err,"%s",s); if (!gos_lower) gos_lower = glk_window_open(0, 0, 0, wintype_TextBuffer, 0); glk_set_window(gos_lower); glk_set_style(style_Normal); glk_put_string("\n\nFatal error: "); glk_put_string(err); glk_put_string("\n"); glk_exit(); }
/*====================================================================== terminate() Terminate the execution of the adventure, e.g. close windows, return buffers... */ void terminate(int code) { newline(); terminateStateStack(); stopTranscript(); if (memory) deallocate(memory); #ifdef HAVE_GLK glk_exit(); #else exit(code); #endif }
void on_quit_activate(GtkMenuItem *unused_menuitem, gpointer unused_data) { GglkText *tb = GGLK_TEXT(gglk_get_line_input_view()); if(tb) do_set_text("quit", TRUE); else { GtkWidget *dialog; GtkResponseType response; dialog = gtk_message_dialog_new(GTK_WINDOW(gglk_win), GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, "Are you sure you want to quit?"); response = gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); if(response == GTK_RESPONSE_YES) glk_exit(); } }
void die(const char *fmt, ...) { va_list ap; char str[1024]; va_start(ap, fmt); vsnprintf(str, sizeof str, fmt, ap); va_end(ap); show_message("fatal error: %s", str); #ifdef ZTERP_GLK #ifdef GARGLK fprintf(stderr, "%s\n", str); #endif glk_exit(); #endif exit(EXIT_FAILURE); }
static int PerformActions(int vb,int no) { static int disable_sysfunc=0; /* Recursion lock */ int d=BitFlags&(1<<DARKBIT); int ct=0; int fl; int doagain=0; if(vb==1 && no == -1 ) { Output("Give me a direction too."); return(0); } if(vb==1 && no>=1 && no<=6) { int nl; if(Items[LIGHT_SOURCE].Location==MyLoc || Items[LIGHT_SOURCE].Location==CARRIED) d=0; if(d) Output("Dangerous to move in the dark! "); nl=Rooms[MyLoc].Exits[no-1]; if(nl!=0) { MyLoc=nl; return(0); } if(d) { if(Options&YOUARE) Output("You fell down and broke your neck. "); else Output("I fell down and broke my neck. "); glk_exit(); } if(Options&YOUARE) Output("You can't go in that direction. "); else Output("I can't go in that direction. "); return(0); } fl= -1; while(ct<=GameHeader.NumActions) { int vv,nv; vv=Actions[ct].Vocab; /* Think this is now right. If a line we run has an action73 run all following lines with vocab of 0,0 */ if(vb!=0 && (doagain&&vv!=0)) break; /* Oops.. added this minor cockup fix 1.11 */ if(vb!=0 && !doagain && fl== 0) break; nv=vv%150; vv/=150; if((vv==vb)||(doagain&&Actions[ct].Vocab==0)) { if((vv==0 && RandomPercent(nv))||doagain|| (vv!=0 && (nv==no||nv==0))) { int f2; if(fl== -1) fl= -2; if((f2=PerformLine(ct))>0) { /* ahah finally figured it out ! */ fl=0; if(f2==2) doagain=1; if(vb!=0 && doagain==0) return(0); } } } ct++; /* Previously this did not check ct against * GameHeader.NumActions and would read past the end of * Actions. I don't know what should happen on the last * action, but doing nothing is better than reading one * past the end. * --Chris */ if(ct <= GameHeader.NumActions && Actions[ct].Vocab!=0) doagain=0; } if(fl!=0 && disable_sysfunc==0) { int item; if(Items[LIGHT_SOURCE].Location==MyLoc || Items[LIGHT_SOURCE].Location==CARRIED) d=0; if(vb==10 || vb==18) { /* Yes they really _are_ hardcoded values */ if(vb==10) { if(xstrcasecmp(NounText,"ALL")==0) { int i=0; int f=0; if(d) { Output("It is dark.\n"); return 0; } while(i<=GameHeader.NumItems) { if(Items[i].Location==MyLoc && Items[i].AutoGet!=NULL && Items[i].AutoGet[0]!='*') { no=WhichWord(Items[i].AutoGet,Nouns); disable_sysfunc=1; /* Don't recurse into auto get ! */ PerformActions(vb,no); /* Recursively check each items table code */ disable_sysfunc=0; if(CountCarried()==GameHeader.MaxCarry) { if(Options&YOUARE) Output("You are carrying too much. "); else Output("I've too much to carry. "); return(0); } Items[i].Location= CARRIED; Output(Items[i].Text); Output(": O.K.\n"); f=1; } i++; } if(f==0) Output("Nothing taken."); return(0); } if(no==-1) { Output("What ? "); return(0); } if(CountCarried()==GameHeader.MaxCarry) { if(Options&YOUARE) Output("You are carrying too much. "); else Output("I've too much to carry. "); return(0); } item=MatchUpItem(NounText,MyLoc); if(item==-1) { if(Options&YOUARE) Output("It is beyond your power to do that. "); else Output("It's beyond my power to do that. "); return(0); } Items[item].Location= CARRIED; Output("O.K. "); return(0); } if(vb==18) { if(xstrcasecmp(NounText,"ALL")==0) { int i=0; int f=0; while(i<=GameHeader.NumItems) { if(Items[i].Location==CARRIED && Items[i].AutoGet && Items[i].AutoGet[0]!='*') { no=WhichWord(Items[i].AutoGet,Nouns); disable_sysfunc=1; PerformActions(vb,no); disable_sysfunc=0; Items[i].Location=MyLoc; Output(Items[i].Text); Output(": O.K.\n"); f=1; } i++; } if(f==0) Output("Nothing dropped.\n"); return(0); } if(no==-1) { Output("What ? "); return(0); } item=MatchUpItem(NounText,CARRIED); if(item==-1) { if(Options&YOUARE) Output("It's beyond your power to do that.\n"); else Output("It's beyond my power to do that.\n"); return(0); } Items[item].Location=MyLoc; Output("O.K. "); return(0); } } } return(fl); }
static int PerformLine(int ct) { int continuation=0; int param[5],pptr=0; int act[4]; int cc=0; while(cc<5) { int cv,dv; cv=Actions[ct].Condition[cc]; dv=cv/20; cv%=20; switch(cv) { case 0: param[pptr++]=dv; break; case 1: if(Items[dv].Location!=CARRIED) return(0); break; case 2: if(Items[dv].Location!=MyLoc) return(0); break; case 3: if(Items[dv].Location!=CARRIED&& Items[dv].Location!=MyLoc) return(0); break; case 4: if(MyLoc!=dv) return(0); break; case 5: if(Items[dv].Location==MyLoc) return(0); break; case 6: if(Items[dv].Location==CARRIED) return(0); break; case 7: if(MyLoc==dv) return(0); break; case 8: if((BitFlags&(1<<dv))==0) return(0); break; case 9: if(BitFlags&(1<<dv)) return(0); break; case 10: if(CountCarried()==0) return(0); break; case 11: if(CountCarried()) return(0); break; case 12: if(Items[dv].Location==CARRIED||Items[dv].Location==MyLoc) return(0); break; case 13: if(Items[dv].Location==0) return(0); break; case 14: if(Items[dv].Location) return(0); break; case 15: if(CurrentCounter>dv) return(0); break; case 16: if(CurrentCounter<=dv) return(0); break; case 17: if(Items[dv].Location!=Items[dv].InitialLoc) return(0); break; case 18: if(Items[dv].Location==Items[dv].InitialLoc) return(0); break; case 19:/* Only seen in Brian Howarth games so far */ if(CurrentCounter!=dv) return(0); break; } cc++; } /* Actions */ act[0]=Actions[ct].Action[0]; act[2]=Actions[ct].Action[1]; act[1]=act[0]%150; act[3]=act[2]%150; act[0]/=150; act[2]/=150; cc=0; pptr=0; while(cc<4) { if(act[cc]>=1 && act[cc]<52) { Output(Messages[act[cc]]); Output("\n"); } else if(act[cc]>101) { Output(Messages[act[cc]-50]); Output("\n"); } else switch(act[cc]) { case 0:/* NOP */ break; case 52: if(CountCarried()==GameHeader.MaxCarry) { if(Options&YOUARE) Output("You are carrying too much. "); else Output("I've too much to carry! "); break; } Items[param[pptr++]].Location= CARRIED; break; case 53: Items[param[pptr++]].Location=MyLoc; break; case 54: MyLoc=param[pptr++]; break; case 55: Items[param[pptr++]].Location=0; break; case 56: BitFlags|=1<<DARKBIT; break; case 57: BitFlags&=~(1<<DARKBIT); break; case 58: BitFlags|=(1<<param[pptr++]); break; case 59: Items[param[pptr++]].Location=0; break; case 60: BitFlags&=~(1<<param[pptr++]); break; case 61: if(Options&YOUARE) Output("You are dead.\n"); else Output("I am dead.\n"); BitFlags&=~(1<<DARKBIT); MyLoc=GameHeader.NumRooms;/* It seems to be what the code says! */ break; case 62: { /* Bug fix for some systems - before it could get parameters wrong */ int i=param[pptr++]; Items[i].Location=param[pptr++]; break; } case 63: doneit: Output("The game is now over.\n"); glk_exit(); case 64: break; case 65: { int i=0; int n=0; while(i<=GameHeader.NumItems) { if(Items[i].Location==GameHeader.TreasureRoom && *Items[i].Text=='*') n++; i++; } if(Options&YOUARE) Output("You have stored "); else Output("I've stored "); OutputNumber(n); Output(" treasures. On a scale of 0 to 100, that rates "); OutputNumber((n*100)/GameHeader.Treasures); Output(".\n"); if(n==GameHeader.Treasures) { Output("Well done.\n"); goto doneit; } break; } case 66: { int i=0; int f=0; if(Options&YOUARE) Output("You are carrying:\n"); else Output("I'm carrying:\n"); while(i<=GameHeader.NumItems) { if(Items[i].Location==CARRIED) { if(f==1) { if (Options & TRS80_STYLE) Output(". "); else Output(" - "); } f=1; Output(Items[i].Text); } i++; } if(f==0) Output("Nothing"); Output(".\n"); break; } case 67: BitFlags|=(1<<0); break; case 68: BitFlags&=~(1<<0); break; case 69: GameHeader.LightTime=LightRefill; Items[LIGHT_SOURCE].Location=CARRIED; BitFlags&=~(1<<LIGHTOUTBIT); break; case 70: ClearScreen(); /* pdd. */ break; case 71: SaveGame(); break; case 72: { int i1=param[pptr++]; int i2=param[pptr++]; int t=Items[i1].Location; Items[i1].Location=Items[i2].Location; Items[i2].Location=t; break; } case 73: continuation=1; break; case 74: Items[param[pptr++]].Location= CARRIED; break; case 75: { int i1,i2; i1=param[pptr++]; i2=param[pptr++]; Items[i1].Location=Items[i2].Location; break; } case 76: /* Looking at adventure .. */ break; case 77: if(CurrentCounter>=0) CurrentCounter--; break; case 78: OutputNumber(CurrentCounter); break; case 79: CurrentCounter=param[pptr++]; break; case 80: { int t=MyLoc; MyLoc=SavedRoom; SavedRoom=t; break; } case 81: { /* This is somewhat guessed. Claymorgue always seems to do select counter n, thing, select counter n, but uses one value that always seems to exist. Trying a few options I found this gave sane results on ageing */ int t=param[pptr++]; int c1=CurrentCounter; CurrentCounter=Counters[t]; Counters[t]=c1; break; } case 82: CurrentCounter+=param[pptr++]; break; case 83: CurrentCounter-=param[pptr++]; if(CurrentCounter< -1) CurrentCounter= -1; /* Note: This seems to be needed. I don't yet know if there is a maximum value to limit too */ break; case 84: Output(NounText); break; case 85: Output(NounText); Output("\n"); break; case 86: Output("\n"); break; case 87: { /* Changed this to swap location<->roomflag[x] not roomflag 0 and x */ int p=param[pptr++]; int sr=MyLoc; MyLoc=RoomSaved[p]; RoomSaved[p]=sr; break; } case 88: delay(2); break; case 89: pptr++; /* SAGA draw picture n */ /* Spectrum Seas of Blood - start combat ? */ /* Poking this into older spectrum games causes a crash */ break; default: fprintf(stderr,"Unknown action %d [Param begins %d %d]\n", act[cc],param[pptr],param[pptr+1]); break; } cc++; } return(1+continuation); }
void glk_main(void) { FILE *f; int vb,no; Bottom = glk_window_open(0, 0, 0, wintype_TextBuffer, 1); if(Bottom == NULL) glk_exit(); glk_set_window(Bottom); if(game_file == NULL) Fatal("No game provided"); f = fopen(game_file, "r"); if(f==NULL) Fatal("Cannot open game"); if (Options & TRS80_STYLE) { Width = 64; TopHeight = 11; } else { Width = 80; TopHeight = 10; } if(split_screen) { Top = glk_window_open(Bottom, winmethod_Above | winmethod_Fixed, TopHeight, wintype_TextGrid, 0); if(Top == NULL) { split_screen = 0; Top = Bottom; } } else { Top = Bottom; } Output("\ Scott Free, A Scott Adams game driver in C.\n\ Release 1.14, (c) 1993,1994,1995 Swansea University Computer Society.\n\ Distributed under the GNU software license\n\n"); LoadDatabase(f,(Options&DEBUGGING)?1:0); fclose(f); srand(time(NULL)); while(1) { glk_tick(); PerformActions(0,0); Look(); if(GetInput(&vb,&no) == -1) continue; switch(PerformActions(vb,no)) { case -1:Output("I don't understand your command. "); break; case -2:Output("I can't do that yet. "); break; } /* Brian Howarth games seem to use -1 for forever */ if(Items[LIGHT_SOURCE].Location/*==-1*/!=DESTROYED && GameHeader.LightTime!= -1) { GameHeader.LightTime--; if(GameHeader.LightTime<1) { BitFlags|=(1<<LIGHTOUTBIT); if(Items[LIGHT_SOURCE].Location==CARRIED || Items[LIGHT_SOURCE].Location==MyLoc) { if(Options&SCOTTLIGHT) Output("Light has run out! "); else Output("Your light has run out. "); } if(Options&PREHISTORIC_LAMP) Items[LIGHT_SOURCE].Location=DESTROYED; } else if(GameHeader.LightTime<25) { if(Items[LIGHT_SOURCE].Location==CARRIED || Items[LIGHT_SOURCE].Location==MyLoc) { if(Options&SCOTTLIGHT) { Output("Light runs out in "); OutputNumber(GameHeader.LightTime); Output(" turns. "); } else { if(GameHeader.LightTime%5==0) Output("Your light is growing dim. "); } } } } } }
static void Fatal(const char *x) { wprintf(Bottom, "%s\n", x); glk_exit(); }
void os_process_arguments(int argc, char *argv[]) { int c; #ifdef GARGLK garglk_set_program_name("Frotz " VERSION); garglk_set_program_info( "Glk Frotz " VERSION "\n" "Original Frotz by Stefan Jokisch\n" "Unix port by Jim Dunleavy and David Griffith\n" "Glk port by Tor Andersson\n"); #endif /* Parse the options */ do { c = zgetopt(argc, argv, "aAioOPQs:S:tu:xZ:"); switch (c) { case 'a': option_attribute_assignment = 1; break; case 'A': option_attribute_testing = 1; break; case 'i': option_ignore_errors = 1; break; case 'o': option_object_movement = 1; break; case 'O': option_object_locating = 1; break; case 'P': option_piracy = 1; break; case 'Q': option_save_quetzal = 0; break; case 's': user_random_seed = atoi(zoptarg); break; case 'S': option_script_cols = atoi(zoptarg); break; case 't': user_tandy_bit = 1; break; case 'u': option_undo_slots = atoi(zoptarg); break; case 'x': option_expand_abbreviations = 1; break; case 'Z': option_err_report_mode = atoi(zoptarg); if ((option_err_report_mode < ERR_REPORT_NEVER) || (option_err_report_mode > ERR_REPORT_FATAL)) option_err_report_mode = ERR_DEFAULT_REPORT_MODE; break; } } while (c != EOF); if (((argc - zoptind) != 1) && ((argc - zoptind) != 2)) { winid_t win; char buf[256]; win = glk_window_open(0, 0, 0, wintype_TextBuffer, 0); glk_set_window(win); glk_put_string("FROTZ V" VERSION " -- Glk 0.7.0 interface.\n"); glk_put_string(INFORMATION); sprintf(buf, " -Z # error checking mode (default = %d)\n" " %d = don't report errors. " "%d = report first error.\n" " %d = report all errors. " "%d = exit after any error.\n", ERR_DEFAULT_REPORT_MODE, ERR_REPORT_NEVER, ERR_REPORT_ONCE, ERR_REPORT_ALWAYS, ERR_REPORT_FATAL); glk_put_string(buf); glk_exit(); } else { char *s; story_name = argv[zoptind++]; if (zoptind < argc) graphics_filename = argv[zoptind++]; #ifdef GARGLK s = strrchr(story_name, '\\'); if (!s) s = strrchr(story_name, '/'); garglk_set_story_name(s ? s + 1 : story_name); #endif } }
int main(int argc, char *argv[]) { int ix, jx, val; glkunix_startup_t startdata; setlocale (LC_CTYPE, ""); /* Test for compile-time errors. If one of these spouts off, you must edit glk.h and recompile. */ if (sizeof(glui32) != 4) { printf("Compile-time error: glui32 is not a 32-bit value. Please fix glk.h.\n"); return 1; } if ((glui32)(-1) < 0) { printf("Compile-time error: glui32 is not unsigned. Please fix glk.h.\n"); return 1; } /* Now some argument-parsing. This is probably going to hurt. */ startdata.argc = 0; startdata.argv = (char **)malloc(argc * sizeof(char *)); /* Copy in the program name. */ startdata.argv[startdata.argc] = argv[0]; startdata.argc++; for (ix=1; ix<argc && !errflag; ix++) { glkunix_argumentlist_t *argform; int inarglist = FALSE; char *cx; for (argform = glkunix_arguments; argform->argtype != glkunix_arg_End && !errflag; argform++) { if (argform->name[0] == '\0') { if (argv[ix][0] != '-') { startdata.argv[startdata.argc] = argv[ix]; startdata.argc++; inarglist = TRUE; } } else if ((argform->argtype == glkunix_arg_NumberValue) && !strncmp(argv[ix], argform->name, strlen(argform->name)) && (cx = argv[ix] + strlen(argform->name)) && (atoi(cx) != 0 || cx[0] == '0')) { startdata.argv[startdata.argc] = argv[ix]; startdata.argc++; inarglist = TRUE; } else if (!strcmp(argv[ix], argform->name)) { int numeat = 0; if (argform->argtype == glkunix_arg_ValueFollows) { if (ix+1 >= argc) { printf("%s: %s must be followed by a value\n", argv[0], argform->name); errflag = TRUE; break; } numeat = 2; } else if (argform->argtype == glkunix_arg_NoValue) { numeat = 1; } else if (argform->argtype == glkunix_arg_ValueCanFollow) { if (ix+1 < argc && argv[ix+1][0] != '-') { numeat = 2; } else { numeat = 1; } } else if (argform->argtype == glkunix_arg_NumberValue) { if (ix+1 >= argc || (atoi(argv[ix+1]) == 0 && argv[ix+1][0] != '0')) { printf("%s: %s must be followed by a number\n", argv[0], argform->name); errflag = TRUE; break; } numeat = 2; } else { errflag = TRUE; break; } for (jx=0; jx<numeat; jx++) { startdata.argv[startdata.argc] = argv[ix]; startdata.argc++; if (jx+1 < numeat) ix++; } inarglist = TRUE; break; } } if (inarglist || errflag) continue; if (argv[ix][0] != '-') { printf("%s: unwanted argument: %s\n", argv[0], argv[ix]); errflag = TRUE; break; } if (extract_value(argc, argv, "?", ex_Void, &ix, &val, FALSE)) errflag = TRUE; else if (extract_value(argc, argv, "help", ex_Void, &ix, &val, FALSE)) errflag = TRUE; else if (extract_value(argc, argv, "version", ex_Void, &ix, &val, FALSE)) pref_printversion = val; else if (extract_value(argc, argv, "v", ex_Void, &ix, &val, FALSE)) pref_printversion = val; else if (extract_value(argc, argv, "historylen", ex_Int, &ix, &val, 20)) pref_historylen = val; else if (extract_value(argc, argv, "hl", ex_Int, &ix, &val, 20)) pref_historylen = val; else if (extract_value(argc, argv, "width", ex_Int, &ix, &val, 80)) pref_screenwidth = val; else if (extract_value(argc, argv, "w", ex_Int, &ix, &val, 80)) pref_screenwidth = val; else if (extract_value(argc, argv, "height", ex_Int, &ix, &val, 24)) pref_screenheight = val; else if (extract_value(argc, argv, "h", ex_Int, &ix, &val, 24)) pref_screenheight = val; else if (extract_value(argc, argv, "ml", ex_Bool, &ix, &val, pref_messageline)) pref_messageline = val; else if (extract_value(argc, argv, "revgrid", ex_Bool, &ix, &val, pref_reverse_textgrids)) pref_reverse_textgrids = val; else if (extract_value(argc, argv, "border", ex_Bool, &ix, &val, pref_window_borders)) pref_window_borders = val; else if (extract_value(argc, argv, "defprompt", ex_Bool, &ix, &val, pref_prompt_defaults)) pref_prompt_defaults = val; #ifdef OPT_TIMED_INPUT else if (extract_value(argc, argv, "precise", ex_Bool, &ix, &val, pref_precise_timing)) pref_precise_timing = val; #endif /* !OPT_TIMED_INPUT */ else { printf("%s: unknown option: %s\n", argv[0], argv[ix]); errflag = TRUE; } } if (errflag) { printf("usage: %s [ options ... ]\n", argv[0]); if (glkunix_arguments[0].argtype != glkunix_arg_End) { glkunix_argumentlist_t *argform; printf("game options:\n"); for (argform = glkunix_arguments; argform->argtype != glkunix_arg_End; argform++) { printf(" %s\n", argform->desc); } } printf("library options:\n"); printf(" -width NUM: manual screen width (if not specified, will try to measure)\n"); printf(" -height NUM: manual screen height (ditto)\n"); printf(" -ml BOOL: use message line (default 'yes')\n"); printf(" -historylen NUM: length of command history (default 20)\n"); printf(" -revgrid BOOL: reverse text in grid (status) windows (default 'no')\n"); printf(" -border BOOL: draw borders between windows (default 'yes')\n"); printf(" -defprompt BOOL: provide defaults for file prompts (default 'yes')\n"); #ifdef OPT_TIMED_INPUT printf(" -precise BOOL: more precise timing for timed input (burns more CPU time) (default 'no')\n"); #endif /* !OPT_TIMED_INPUT */ printf(" -version: display Glk library version\n"); printf(" -help: display this list\n"); printf("NUM values can be any number. BOOL values can be 'yes' or 'no', or no value to toggle.\n"); return 1; } if (pref_printversion) { printf("GlkTerm, library version %s (%s).\n", LIBRARY_VERSION, LIBRARY_PORT); printf("For more information, see http://eblong.com/zarf/glk/index.html\n"); return 1; } /* We now start up curses. From now on, the program must exit through glk_exit(), so that endwin() is called. */ gli_setup_curses(); /* Initialize things. */ gli_initialize_misc(); gli_initialize_windows(); gli_initialize_events(); inittime = TRUE; if (!glkunix_startup_code(&startdata)) { glk_exit(); } inittime = FALSE; /* Call the program main entry point, and then exit. */ glk_main(); glk_exit(); /* glk_exit() doesn't return, but the compiler may kvetch if main() doesn't seem to return a value. */ return 0; }
static void Fatal(char *x) { wprintw(Bottom, "%s", x); glk_exit(); }
void gidispatch_call(glui32 funcnum, glui32 numargs, gluniversal_t *arglist) { gidispatch_function_t *gidispatch_function; char *prototype; int argument = 0; int slot = 0; gidispatch_function = gidispatch_get_function_by_id(funcnum); prototype = gidispatch_prototype(funcnum); printf("DEBUG: dispatch call name=%s, prototype=%s, numargs=%u -- ", gidispatch_function->name, prototype, (unsigned int)numargs); if (strcmp(prototype, "4IuIuIuIs") == 0) { printf("%u, %u, %u, %d\n", arglist[0].uint, arglist[1].uint, arglist[2].uint, arglist[3].sint); } else if (strcmp(prototype, "3IuIu:Iu") == 0) { printf("%u, %u, returning a glui32\n", arglist[0].uint, arglist[1].uint); } else if (strcmp(prototype, "3Qa<Iu:Qa") == 0) { printf("win at %p, outref to a glui32, returning a winid_t\n", arglist[0].opaqueref); } else if (strcmp(prototype, "3Qc<Iu:Qc") == 0) { printf("fileref at %p, outref to a glui32, returning a frefid_t\n", arglist[0].opaqueref); } else if (strcmp(prototype, "1Qa:") == 0) { printf("win at %p\n", arglist[0].opaqueref); } else if (strcmp(prototype, "6QaIuIuIuIu:Qa") == 0) { printf("win at %p, %u, %u, %u, %u, returning a winid_t\n", arglist[0].opaqueref, arglist[1].uint, arglist[2].uint, arglist[3].uint, arglist[4].uint); } else if (strcmp(prototype, "4IuIuIuIs:") == 0) { printf("%u, %u, %u, %d\n", arglist[0].uint, arglist[1].uint, arglist[2].uint, arglist[3].sint); } else if (strcmp(prototype, "1Qb:") == 0) { printf("stream at %p\n", arglist[0].opaqueref); } else if (strcmp(prototype, "1Iu:") == 0) { printf("%u\n", arglist[0].uint); } else if (strcmp(prototype, "2Qb<[2IuIu]:") == 0) { printf("stream at %p, some struct stuff here\n", arglist[0].opaqueref); } else if (strcmp(prototype, "3IuIuIu:") == 0) { printf("%u, %u, %u\n", arglist[0].uint, arglist[1].uint, arglist[2].uint); } else if (strcmp(prototype, "1:Qb") == 0) { printf("returning a strid_t\n"); } else if (strcmp(prototype, "4&+#!IuIuIu:Qb") == 0) { printf("retained, nonnull, array of glui32 at %p for length %u, %u, %u, returning a strid_t\n", arglist[1].array, arglist[2].uint, arglist[3].uint, arglist[4].uint); } else if (strcmp(prototype, "2Qc:Iu") == 0) { printf("fileref at %p, returning a glui32\n", arglist[0].opaqueref); } else if (strcmp(prototype, "1<+[4IuQaIuIu]:") == 0) { printf("some struct stuff here, nonnull\n"); } else if (strcmp(prototype, "1:Qb") == 0) { printf("returning a strid_t\n"); } else if (strcmp(prototype, "2Qb:Is") == 0) { printf("stream at %p, returning a glsi32\n", arglist[0].opaqueref); } else if (strcmp(prototype, "2Qc:Iu") == 0) { printf("fileref at %p, returning a glui32\n", arglist[0].opaqueref); } else if (strcmp(prototype, "3Qa&+#!CnIu:") == 0) { printf("win at %p, retained, nonnull, array of char at %p for length %u, %u\n", arglist[0].opaqueref, arglist[2].array, arglist[3].uint, arglist[4].uint); } else if (strcmp(prototype, "3Qb<Iu:Qb") == 0) { printf("stream at %p, outref to a glui32, returning a strid_t\n", arglist[0].opaqueref); } else if (strcmp(prototype, "4&+#!CnIuIu:Qb") == 0) { printf("retained, nonnull, array of char at %p for length %u, %u, %u, returning a strid_t\n", arglist[1].array, arglist[2].uint, arglist[3].uint, arglist[4].uint); } else if (strcmp(prototype, "4&+#!IuIuIu:Qb") == 0) { printf("retained, nonnull, array of glui32 at %p for length %u, %u, %u, returning a strid_t\n", arglist[1].array, arglist[2].uint, arglist[3].uint, arglist[4].uint); } else if (strcmp(prototype, "4IuSIu:Qc") == 0) { printf("%u, %s, %u, returning a frefid_t\n", arglist[0].uint, arglist[1].charstr, arglist[2].uint); } else if (strcmp(prototype, "4QcIuIu:Qb") == 0) { printf("fileref at %p, %u, %u, returning a strid_t\n", arglist[0].opaqueref, arglist[1].uint, arglist[2].uint); } else if (strcmp(prototype, "3Qa<Iu<Iu:") == 0) { printf("win at %p, outref to a glui32, outref to a glui32\n", arglist[0].opaqueref); } else if (strcmp(prototype, "6QaIuIsIsIuIu:") == 0) { printf("win at %p, %u, %d, %d, %u, %u\n", arglist[0].opaqueref, arglist[1].uint, arglist[2].sint, arglist[3].sint, arglist[4].uint, arglist[5].uint); } else if (strcmp(prototype, "4Iu<Iu<Iu:Iu") == 0) { printf("%u, outref to a glui32, outref to a glui32, returning a glui32\n", arglist[0].uint); } else { printf("unhandled prototype\n"); } switch (funcnum) { case 0x0004: /* gestalt */ arglist[3].uint = glk_gestalt(arglist[0].uint, arglist[1].uint); break; case 0x0005: /* gestalt_ext */ if (arglist[2].ptrflag) { arglist[6].uint = glk_gestalt_ext(arglist[0].uint, arglist[1].uint, arglist[3].array, arglist[4].uint); } else { arglist[4].uint = glk_gestalt_ext(arglist[0].uint, arglist[1].uint, NULL, 0); } break; case 0x0020: /* window_iterate */ if (arglist[1].ptrflag) arglist[4].opaqueref = glk_window_iterate(arglist[0].opaqueref, &arglist[2].uint); else arglist[3].opaqueref = glk_window_iterate(arglist[0].opaqueref, NULL); break; case 0x0023: /* window_open */ arglist[6].opaqueref = glk_window_open(arglist[0].opaqueref, arglist[1].uint, arglist[2].uint, arglist[3].uint, arglist[4].uint); break; case 0x0025: /* window_get_size */ { int ix = 1; glui32 *ptr1, *ptr2; if (!arglist[ix].ptrflag) { ptr1 = NULL; } else { ix++; ptr1 = &(arglist[ix].uint); } ix++; if (!arglist[ix].ptrflag) { ptr2 = NULL; } else { ix++; ptr2 = &(arglist[ix].uint); } ix++; glk_window_get_size(arglist[0].opaqueref, ptr1, ptr2); } break; case 0x0028: /* window_get_type */ arglist[2].uint = glk_window_get_type(arglist[0].opaqueref); break; case 0x002A: /* window_clear */ glk_window_clear(arglist[0].opaqueref); break; case 0x002B: /* window_move_cursor */ glk_window_move_cursor(arglist[0].opaqueref, arglist[1].uint, arglist[2].uint); break; case 0x002F: /* set_window */ glk_set_window(arglist[0].opaqueref); break; case 0x0040: /* stream_iterate */ if (arglist[1].ptrflag) arglist[4].opaqueref = glk_stream_iterate(arglist[0].opaqueref, &arglist[2].uint); else arglist[3].opaqueref = glk_stream_iterate(arglist[0].opaqueref, NULL); break; case 0x0042: /* stream_open_file */ arglist[4].opaqueref = glk_stream_open_file(arglist[0].opaqueref, arglist[1].uint, arglist[2].uint); break; case 0x0043: /* stream_open_memory */ if (arglist[0].ptrflag) arglist[6].opaqueref = glk_stream_open_memory(arglist[1].array, arglist[2].uint, arglist[3].uint, arglist[4].uint); else arglist[4].opaqueref = glk_stream_open_memory(NULL, 0, arglist[1].uint, arglist[2].uint); break; case 0x0044: /* stream_close */ if (arglist[1].ptrflag) { stream_result_t dat; glk_stream_close(arglist[0].opaqueref, &dat); arglist[2].uint = dat.readcount; arglist[3].uint = dat.writecount; } else { glk_stream_close(arglist[0].opaqueref, NULL); } break; case 0x0047: /* stream_set_current */ glk_stream_set_current(arglist[0].opaqueref); break; case 0x0048: /* stream_get_current */ arglist[1].opaqueref = glk_stream_get_current(); break; case 0x0061: /* fileref_create_by_name */ arglist[4].opaqueref = glk_fileref_create_by_name(arglist[0].uint, arglist[1].charstr, arglist[2].uint); break; case 0x0062: /* fileref_create_by_prompt */ arglist[4].opaqueref = glk_fileref_create_by_prompt(arglist[0].uint, arglist[1].uint, arglist[2].uint); break; case 0x0067: /* fileref_does_file_exist */ arglist[2].uint = glk_fileref_does_file_exist(arglist[0].opaqueref); break; case 0x0086: /* set_style */ glk_set_style(arglist[0].uint); break; case 0x0087: /* set_style_stream */ glk_set_style_stream(arglist[0].opaqueref, arglist[1].uint); break; case 0x0090: /* get_char_stream */ arglist[2].sint = glk_get_char_stream(arglist[0].opaqueref); break; case 0x00B0: /* stylehint_set */ glk_stylehint_set(arglist[0].uint, arglist[1].uint, arglist[2].uint, arglist[3].sint); break; case 0x00C0: /* select */ if (arglist[0].ptrflag) { event_t dat; glk_select(&dat); arglist[1].uint = dat.type; arglist[2].opaqueref = dat.win; arglist[3].uint = dat.val1; arglist[4].uint = dat.val2; } else { glk_select(NULL); } break; case 0x00D0: /* request_line_event */ if (arglist[1].ptrflag) glk_request_line_event(arglist[0].opaqueref, arglist[2].array, arglist[3].uint, arglist[4].uint); else glk_request_line_event(arglist[0].opaqueref, NULL, 0, arglist[2].uint); break; case 0x00D2: /* request_char_event */ glk_request_char_event(arglist[0].opaqueref); break; case 0x00E0: /* image_get_info */ { int ix = 1; glui32 *ptr1, *ptr2; if (!arglist[ix].ptrflag) { ptr1 = NULL; } else { ix++; ptr1 = &(arglist[ix].uint); } ix++; if (!arglist[ix].ptrflag) { ptr2 = NULL; } else { ix++; ptr2 = &(arglist[ix].uint); } ix++; ix++; arglist[ix].uint = glk_image_get_info(arglist[0].uint, ptr1, ptr2); } break; case 0x00E1: /* image_draw */ arglist[5].uint = glk_image_draw(arglist[0].opaqueref, arglist[1].uint, arglist[2].sint, arglist[3].sint); break; case 0x00E2: /* image_draw_scaled */ arglist[7].uint = glk_image_draw_scaled(arglist[0].opaqueref, arglist[1].uint, arglist[2].sint, arglist[3].sint, arglist[4].uint, arglist[5].uint); break; case 0x00EA: /* window_fill_rect */ glk_window_fill_rect(arglist[0].opaqueref, arglist[1].uint, arglist[2].sint, arglist[3].sint, arglist[4].uint, arglist[5].uint); break; case 0x0128: /* put_char_uni */ glk_put_char_uni(arglist[0].uint); break; case 0x0139: /* stream_open_memory_uni */ if (arglist[0].ptrflag) arglist[6].opaqueref = glk_stream_open_memory_uni(arglist[1].array, arglist[2].uint, arglist[3].uint, arglist[4].uint); else arglist[4].opaqueref = glk_stream_open_memory_uni(NULL, 0, arglist[1].uint, arglist[2].uint); break; default: printf("Unhandled call to %s via dispatch\n", gidispatch_function->name); #if 0 case 0x0001: /* exit */ glk_exit(); break; case 0x0002: /* set_interrupt_handler */ /* cannot be invoked through dispatch layer */ break; case 0x0003: /* tick */ glk_tick(); break; case 0x0021: /* window_get_rock */ arglist[2].uint = glk_window_get_rock(arglist[0].opaqueref); break; case 0x0022: /* window_get_root */ arglist[1].opaqueref = glk_window_get_root(); break; case 0x0024: /* window_close */ if (arglist[1].ptrflag) { stream_result_t dat; glk_window_close(arglist[0].opaqueref, &dat); arglist[2].uint = dat.readcount; arglist[3].uint = dat.writecount; } else { glk_window_close(arglist[0].opaqueref, NULL); } break; case 0x0026: /* window_set_arrangement */ glk_window_set_arrangement(arglist[0].opaqueref, arglist[1].uint, arglist[2].uint, arglist[3].opaqueref); break; case 0x0027: /* window_get_arrangement */ { int ix = 1; glui32 *ptr1, *ptr2; winid_t *ptr3; if (!arglist[ix].ptrflag) { ptr1 = NULL; } else { ix++; ptr1 = &(arglist[ix].uint); } ix++; if (!arglist[ix].ptrflag) { ptr2 = NULL; } else { ix++; ptr2 = &(arglist[ix].uint); } ix++; if (!arglist[ix].ptrflag) { ptr3 = NULL; } else { ix++; ptr3 = (winid_t *)(&(arglist[ix].opaqueref)); } ix++; glk_window_get_arrangement(arglist[0].opaqueref, ptr1, ptr2, ptr3); } break; case 0x0029: /* window_get_parent */ arglist[2].opaqueref = glk_window_get_parent(arglist[0].opaqueref); break; case 0x002C: /* window_get_stream */ arglist[2].opaqueref = glk_window_get_stream(arglist[0].opaqueref); break; case 0x002D: /* window_set_echo_stream */ glk_window_set_echo_stream(arglist[0].opaqueref, arglist[1].opaqueref); break; case 0x002E: /* window_get_echo_stream */ arglist[2].opaqueref = glk_window_get_echo_stream(arglist[0].opaqueref); break; case 0x0030: /* window_get_sibling */ arglist[2].opaqueref = glk_window_get_sibling(arglist[0].opaqueref); break; case 0x0041: /* stream_get_rock */ arglist[2].uint = glk_stream_get_rock(arglist[0].opaqueref); break; case 0x0045: /* stream_set_position */ glk_stream_set_position(arglist[0].opaqueref, arglist[1].sint, arglist[2].uint); break; case 0x0046: /* stream_get_position */ arglist[2].uint = glk_stream_get_position(arglist[0].opaqueref); break; case 0x0048: /* stream_get_current */ arglist[1].opaqueref = glk_stream_get_current(); break; case 0x0060: /* fileref_create_temp */ arglist[3].opaqueref = glk_fileref_create_temp(arglist[0].uint, arglist[1].uint); break; case 0x0063: /* fileref_destroy */ glk_fileref_destroy(arglist[0].opaqueref); break; case 0x0064: /* fileref_iterate */ if (arglist[1].ptrflag) arglist[4].opaqueref = glk_fileref_iterate(arglist[0].opaqueref, &arglist[2].uint); else arglist[3].opaqueref = glk_fileref_iterate(arglist[0].opaqueref, NULL); break; case 0x0065: /* fileref_get_rock */ arglist[2].uint = glk_fileref_get_rock(arglist[0].opaqueref); break; case 0x0066: /* fileref_delete_file */ glk_fileref_delete_file(arglist[0].opaqueref); break; case 0x0068: /* fileref_create_from_fileref */ arglist[4].opaqueref = glk_fileref_create_from_fileref(arglist[0].uint, arglist[1].opaqueref, arglist[2].uint); break; case 0x0080: /* put_char */ glk_put_char(arglist[0].uch); break; case 0x0081: /* put_char_stream */ glk_put_char_stream(arglist[0].opaqueref, arglist[1].uch); break; case 0x0082: /* put_string */ glk_put_string(arglist[0].charstr); break; case 0x0083: /* put_string_stream */ glk_put_string_stream(arglist[0].opaqueref, arglist[1].charstr); break; case 0x0084: /* put_buffer */ if (arglist[0].ptrflag) glk_put_buffer(arglist[1].array, arglist[2].uint); else glk_put_buffer(NULL, 0); break; case 0x0085: /* put_buffer_stream */ if (arglist[1].ptrflag) glk_put_buffer_stream(arglist[0].opaqueref, arglist[2].array, arglist[3].uint); else glk_put_buffer_stream(arglist[0].opaqueref, NULL, 0); break; case 0x0091: /* get_line_stream */ if (arglist[1].ptrflag) arglist[5].uint = glk_get_line_stream(arglist[0].opaqueref, arglist[2].array, arglist[3].uint); else arglist[3].uint = glk_get_line_stream(arglist[0].opaqueref, NULL, 0); break; case 0x0092: /* get_buffer_stream */ if (arglist[1].ptrflag) arglist[5].uint = glk_get_buffer_stream(arglist[0].opaqueref, arglist[2].array, arglist[3].uint); else arglist[3].uint = glk_get_buffer_stream(arglist[0].opaqueref, NULL, 0); break; case 0x00A0: /* char_to_lower */ arglist[2].uch = glk_char_to_lower(arglist[0].uch); break; case 0x00A1: /* char_to_upper */ arglist[2].uch = glk_char_to_upper(arglist[0].uch); break; case 0x00B1: /* stylehint_clear */ glk_stylehint_clear(arglist[0].uint, arglist[1].uint, arglist[2].uint); break; case 0x00B2: /* style_distinguish */ arglist[4].uint = glk_style_distinguish(arglist[0].opaqueref, arglist[1].uint, arglist[2].uint); break; case 0x00B3: /* style_measure */ if (arglist[3].ptrflag) arglist[6].uint = glk_style_measure(arglist[0].opaqueref, arglist[1].uint, arglist[2].uint, &(arglist[4].uint)); else arglist[5].uint = glk_style_measure(arglist[0].opaqueref, arglist[1].uint, arglist[2].uint, NULL); break; case 0x00C1: /* select_poll */ if (arglist[0].ptrflag) { event_t dat; glk_select_poll(&dat); arglist[1].uint = dat.type; arglist[2].opaqueref = dat.win; arglist[3].uint = dat.val1; arglist[4].uint = dat.val2; } else { glk_select_poll(NULL); } break; case 0x00D1: /* cancel_line_event */ if (arglist[1].ptrflag) { event_t dat; glk_cancel_line_event(arglist[0].opaqueref, &dat); arglist[2].uint = dat.type; arglist[3].opaqueref = dat.win; arglist[4].uint = dat.val1; arglist[5].uint = dat.val2; } else { glk_cancel_line_event(arglist[0].opaqueref, NULL); } break; case 0x00D3: /* cancel_char_event */ glk_cancel_char_event(arglist[0].opaqueref); break; case 0x00D4: /* request_mouse_event */ glk_request_mouse_event(arglist[0].opaqueref); break; case 0x00D5: /* cancel_mouse_event */ glk_cancel_mouse_event(arglist[0].opaqueref); break; case 0x00D6: /* request_timer_events */ glk_request_timer_events(arglist[0].uint); break; #ifdef GLK_MODULE_IMAGE case 0x00E8: /* window_flow_break */ glk_window_flow_break(arglist[0].opaqueref); break; case 0x00E9: /* window_erase_rect */ glk_window_erase_rect(arglist[0].opaqueref, arglist[1].sint, arglist[2].sint, arglist[3].uint, arglist[4].uint); break; case 0x00EB: /* window_set_background_color */ glk_window_set_background_color(arglist[0].opaqueref, arglist[1].uint); break; #endif /* GLK_MODULE_IMAGE */ #ifdef GLK_MODULE_SOUND case 0x00F0: /* schannel_iterate */ if (arglist[1].ptrflag) arglist[4].opaqueref = glk_schannel_iterate(arglist[0].opaqueref, &arglist[2].uint); else arglist[3].opaqueref = glk_schannel_iterate(arglist[0].opaqueref, NULL); break; case 0x00F1: /* schannel_get_rock */ arglist[2].uint = glk_schannel_get_rock(arglist[0].opaqueref); break; case 0x00F2: /* schannel_create */ arglist[2].opaqueref = glk_schannel_create(arglist[0].uint); break; case 0x00F3: /* schannel_destroy */ glk_schannel_destroy(arglist[0].opaqueref); break; case 0x00F8: /* schannel_play */ arglist[3].uint = glk_schannel_play(arglist[0].opaqueref, arglist[1].uint); break; case 0x00F9: /* schannel_play_ext */ arglist[5].uint = glk_schannel_play_ext(arglist[0].opaqueref, arglist[1].uint, arglist[2].uint, arglist[3].uint); break; case 0x00FA: /* schannel_stop */ glk_schannel_stop(arglist[0].opaqueref); break; case 0x00FB: /* schannel_set_volume */ glk_schannel_set_volume(arglist[0].opaqueref, arglist[1].uint); break; case 0x00FC: /* sound_load_hint */ glk_sound_load_hint(arglist[0].uint, arglist[1].uint); break; #endif /* GLK_MODULE_SOUND */ #ifdef GLK_MODULE_HYPERLINKS case 0x0100: /* set_hyperlink */ glk_set_hyperlink(arglist[0].uint); break; case 0x0101: /* set_hyperlink_stream */ glk_set_hyperlink_stream(arglist[0].opaqueref, arglist[1].uint); break; case 0x0102: /* request_hyperlink_event */ glk_request_hyperlink_event(arglist[0].opaqueref); break; case 0x0103: /* cancel_hyperlink_event */ glk_cancel_hyperlink_event(arglist[0].opaqueref); break; #endif /* GLK_MODULE_HYPERLINKS */ #ifdef GLK_MODULE_UNICODE case 0x0120: /* buffer_to_lower_case_uni */ if (arglist[0].ptrflag) arglist[5].uint = glk_buffer_to_lower_case_uni(arglist[1].array, arglist[2].uint, arglist[3].uint); else arglist[3].uint = glk_buffer_to_lower_case_uni(NULL, 0, arglist[1].uint); break; case 0x0121: /* buffer_to_upper_case_uni */ if (arglist[0].ptrflag) arglist[5].uint = glk_buffer_to_upper_case_uni(arglist[1].array, arglist[2].uint, arglist[3].uint); else arglist[3].uint = glk_buffer_to_upper_case_uni(NULL, 0, arglist[1].uint); break; case 0x0122: /* buffer_to_title_case_uni */ if (arglist[0].ptrflag) arglist[6].uint = glk_buffer_to_title_case_uni(arglist[1].array, arglist[2].uint, arglist[3].uint, arglist[4].uint); else arglist[4].uint = glk_buffer_to_title_case_uni(NULL, 0, arglist[1].uint, arglist[2].uint); break; case 0x0129: /* put_string_uni */ glk_put_string_uni(arglist[0].unicharstr); break; case 0x012A: /* put_buffer_uni */ if (arglist[0].ptrflag) glk_put_buffer_uni(arglist[1].array, arglist[2].uint); else glk_put_buffer_uni(NULL, 0); break; case 0x012B: /* put_char_stream_uni */ glk_put_char_stream_uni(arglist[0].opaqueref, arglist[1].uint); break; case 0x012C: /* put_string_stream_uni */ glk_put_string_stream_uni(arglist[0].opaqueref, arglist[1].unicharstr); break; case 0x012D: /* put_buffer_stream_uni */ if (arglist[1].ptrflag) glk_put_buffer_stream_uni(arglist[0].opaqueref, arglist[2].array, arglist[3].uint); else glk_put_buffer_stream_uni(arglist[0].opaqueref, NULL, 0); break; case 0x0130: /* get_char_stream_uni */ arglist[2].sint = glk_get_char_stream_uni(arglist[0].opaqueref); break; case 0x0131: /* get_buffer_stream_uni */ if (arglist[1].ptrflag) arglist[5].uint = glk_get_buffer_stream_uni(arglist[0].opaqueref, arglist[2].array, arglist[3].uint); else arglist[3].uint = glk_get_buffer_stream_uni(arglist[0].opaqueref, NULL, 0); break; case 0x0132: /* get_line_stream_uni */ if (arglist[1].ptrflag) arglist[5].uint = glk_get_line_stream_uni(arglist[0].opaqueref, arglist[2].array, arglist[3].uint); else arglist[3].uint = glk_get_line_stream_uni(arglist[0].opaqueref, NULL, 0); break; case 0x0138: /* stream_open_file_uni */ arglist[4].opaqueref = glk_stream_open_file_uni(arglist[0].opaqueref, arglist[1].uint, arglist[2].uint); break; case 0x0140: /* request_char_event_uni */ glk_request_char_event_uni(arglist[0].opaqueref); break; case 0x0141: /* request_line_event_uni */ if (arglist[1].ptrflag) glk_request_line_event_uni(arglist[0].opaqueref, arglist[2].array, arglist[3].uint, arglist[4].uint); else glk_request_line_event_uni(arglist[0].opaqueref, NULL, 0, arglist[2].uint); break; #endif /* GLK_MODULE_UNICODE */ #endif /* 0 */ } }
void glk_main(void) { /* Open the main window. */ mainwin = glk_window_open(0, 0, 0, wintype_TextBuffer, 1); if (!mainwin) { /* It's possible that the main window failed to open. There's nothing we can do without it, so exit. */ return; } glui32 buffer[1024]; int i; for(i = 0; i < 512; i++) { buffer[i * 2] = i + 33; buffer[i * 2 + 1] = 32; } /* frefid_t f = glk_fileref_create_temp(fileusage_BinaryMode, 0); if(f) { strid_t s = glk_stream_open_file(f, filemode_ReadWrite, 0);*/ glui32 membuf[512]; strid_t s = glk_stream_open_memory_uni(membuf, 512, filemode_ReadWrite, 0); glk_stream_set_current(s); glk_put_char_uni('X'); glk_put_string("Philip en Marijn zijn vet goed.\n"); glk_put_buffer_uni(buffer, 1024); glk_stream_set_position(s, 0, seekmode_Start); glk_set_window(mainwin); glk_put_char_uni( glk_get_char_stream_uni(s) ); glk_put_char('\n'); printf("Line read: %d\n", glk_get_line_stream_uni(s, buffer, 1024) ); printf("string[5] = %X\n", buffer[5]); glk_put_string_uni(buffer); int count = glk_get_buffer_stream_uni(s, buffer, 1024); printf("Buffer read: %d\n", count); glk_put_string("\n---SOME CHARACTERS---\n"); glk_put_buffer_uni(buffer, count); glk_put_string("\n---THE SAME CHARACTERS IN UPPERCASE---\n"); int newcount = glk_buffer_to_upper_case_uni(buffer, 1024, 1024); glk_put_buffer_uni(buffer, newcount); stream_result_t result; glk_stream_close(s, &result); fprintf(stderr, "Read count: %d\nWrite count: %d\n", result.readcount, result.writecount); /* glk_fileref_destroy(f); }*/ glk_set_interrupt_handler(&sayit); event_t ev; while(1) { glk_put_string("\nprompt> "); glk_request_line_event_uni(mainwin, buffer, 1024, 0); glk_select(&ev); switch(ev.type) { default: printf("Received event:\n"); printf("Type: %d\n", ev.type); printf("Win: %d\n", glk_window_get_rock(ev.win) ); printf("Var1: %d\n", ev.val1); printf("Var2: %d\n", ev.val2); } } /* Bye bye */ glk_exit(); }
int main(int argc, char *argv[]) { int ix, jx, val; glkunix_startup_t startdata; /* Test for compile-time errors. If one of these spouts off, you must edit glk.h and recompile. */ if (sizeof(glui32) != 4) { printf("Compile-time error: glui32 is not a 32-bit value. Please fix glk.h.\n"); return 1; } if ((glui32)(-1) < 0) { printf("Compile-time error: glui32 is not unsigned. Please fix glk.h.\n"); return 1; } /* Now some argument-parsing. This is probably going to hurt. */ startdata.argc = 0; startdata.argv = (char **)malloc(argc * sizeof(char *)); /* Copy in the program name. */ startdata.argv[startdata.argc] = argv[0]; startdata.argc++; for (ix=1; ix<argc && !errflag; ix++) { glkunix_argumentlist_t *argform; int inarglist = FALSE; char *cx; for (argform = glkunix_arguments; argform->argtype != glkunix_arg_End && !errflag; argform++) { if (argform->name[0] == '\0') { if (argv[ix][0] != '-') { startdata.argv[startdata.argc] = argv[ix]; startdata.argc++; inarglist = TRUE; } } else if ((argform->argtype == glkunix_arg_NumberValue) && !strncmp(argv[ix], argform->name, strlen(argform->name)) && (cx = argv[ix] + strlen(argform->name)) && (atoi(cx) != 0 || cx[0] == '0')) { startdata.argv[startdata.argc] = argv[ix]; startdata.argc++; inarglist = TRUE; } else if (!strcmp(argv[ix], argform->name)) { int numeat = 0; if (argform->argtype == glkunix_arg_ValueFollows) { if (ix+1 >= argc) { printf("%s: %s must be followed by a value\n", argv[0], argform->name); errflag = TRUE; break; } numeat = 2; } else if (argform->argtype == glkunix_arg_NoValue) { numeat = 1; } else if (argform->argtype == glkunix_arg_ValueCanFollow) { if (ix+1 < argc && argv[ix+1][0] != '-') { numeat = 2; } else { numeat = 1; } } else if (argform->argtype == glkunix_arg_NumberValue) { if (ix+1 >= argc || (atoi(argv[ix+1]) == 0 && argv[ix+1][0] != '0')) { printf("%s: %s must be followed by a number\n", argv[0], argform->name); errflag = TRUE; break; } numeat = 2; } else { errflag = TRUE; break; } for (jx=0; jx<numeat; jx++) { startdata.argv[startdata.argc] = argv[ix]; startdata.argc++; if (jx+1 < numeat) ix++; } inarglist = TRUE; break; } } if (inarglist || errflag) continue; if (argv[ix][0] != '-') { printf("%s: unwanted argument: %s\n", argv[0], argv[ix]); errflag = TRUE; break; } if (extract_value(argc, argv, "?", ex_Void, &ix, &val, FALSE)) errflag = TRUE; else if (extract_value(argc, argv, "help", ex_Void, &ix, &val, FALSE)) errflag = TRUE; else if (extract_value(argc, argv, "version", ex_Void, &ix, &val, FALSE)) pref_printversion = val; else if (extract_value(argc, argv, "v", ex_Void, &ix, &val, FALSE)) pref_printversion = val; else if (extract_value(argc, argv, "fixmetrics", ex_Bool, &ix, &val, FALSE)) pref_fixedmetrics = val; else if (extract_value(argc, argv, "fm", ex_Bool, &ix, &val, FALSE)) pref_fixedmetrics = val; else if (extract_value(argc, argv, "width", ex_Int, &ix, &val, 80)) pref_screenwidth = val; else if (extract_value(argc, argv, "w", ex_Int, &ix, &val, 80)) pref_screenwidth = val; else if (extract_value(argc, argv, "height", ex_Int, &ix, &val, 50)) pref_screenheight = val; else if (extract_value(argc, argv, "h", ex_Int, &ix, &val, 50)) pref_screenheight = val; else if (extract_value(argc, argv, "stderr", ex_Bool, &ix, &val, FALSE)) pref_stderr = val; else if (extract_value(argc, argv, "support", ex_Str, &ix, &val, FALSE)) { if (!strcmp(extracted_string, "timer") || !strcmp(extracted_string, "timers")) pref_timersupport = TRUE; else if (!strcmp(extracted_string, "hyperlink") || !strcmp(extracted_string, "hyperlinks")) pref_hyperlinksupport = TRUE; else if (!strcmp(extracted_string, "graphics")) pref_graphicssupport = TRUE; else if (!strcmp(extracted_string, "graphicswin")) pref_graphicswinsupport = TRUE; else { printf("%s: -support value not recognized: %s\n", argv[0], extracted_string); errflag = TRUE; } } else if (extract_value(argc, argv, "resourcedir", ex_Str, &ix, &val, FALSE)) pref_resourceurl = construct_resourceurl(extracted_string, TRUE); else if (extract_value(argc, argv, "rd", ex_Str, &ix, &val, FALSE)) pref_resourceurl = construct_resourceurl(extracted_string, TRUE); else if (extract_value(argc, argv, "resourceurl", ex_Str, &ix, &val, FALSE)) pref_resourceurl = construct_resourceurl(extracted_string, FALSE); else if (extract_value(argc, argv, "ru", ex_Str, &ix, &val, FALSE)) pref_resourceurl = construct_resourceurl(extracted_string, FALSE); #if GIDEBUG_LIBRARY_SUPPORT else if (extract_value(argc, argv, "D", ex_Void, &ix, &val, FALSE)) gli_debugger = val; #endif /* GIDEBUG_LIBRARY_SUPPORT */ else { printf("%s: unknown option: %s\n", argv[0], argv[ix]); errflag = TRUE; } } if (errflag) { printf("usage: %s [ options ... ]\n", argv[0]); if (glkunix_arguments[0].argtype != glkunix_arg_End) { glkunix_argumentlist_t *argform; printf("game options:\n"); for (argform = glkunix_arguments; argform->argtype != glkunix_arg_End; argform++) { if (strlen(argform->name) == 0) printf(" %s\n", argform->desc); else if (argform->argtype == glkunix_arg_ValueFollows) printf(" %s val: %s\n", argform->name, argform->desc); else if (argform->argtype == glkunix_arg_NumberValue) printf(" %s val: %s\n", argform->name, argform->desc); else if (argform->argtype == glkunix_arg_ValueCanFollow) printf(" %s [val]: %s\n", argform->name, argform->desc); else printf(" %s: %s\n", argform->name, argform->desc); } } printf("library options:\n"); printf(" -fixmetrics BOOL: define screen size manually (default 'no')\n"); printf(" -width NUM: manual screen width (default 80)\n"); printf(" -height NUM: manual screen height (default 50)\n"); printf(" -support [timer, hyperlinks, graphics, graphicswin]: declare support for various input features\n"); printf(" -resourceurl STR: URL base for image/sound files\n"); printf(" -resourcedir STR: path to image/sound files (used to create file: URLs)\n"); printf(" -stderr BOOL: send errors to stderr rather than stdout (default 'no')\n"); #if GIDEBUG_LIBRARY_SUPPORT printf(" -D: turn on debug console\n"); #endif /* GIDEBUG_LIBRARY_SUPPORT */ printf(" -version: display Glk library version\n"); printf(" -help: display this list\n"); printf("NUM values can be any number. BOOL values can be 'yes' or 'no', or no value to toggle.\n"); return 1; } if (pref_printversion) { printf("RemGlk, library version %s.\n", LIBRARY_VERSION); printf("For more information, see http://eblong.com/zarf/glk/\n"); return 1; } gli_initialize_datainput(); data_metrics_t *metrics = data_metrics_alloc(pref_screenwidth, pref_screenheight); if (!pref_fixedmetrics) { data_event_t *data = data_event_read(); if (data->dtag != dtag_Init) gli_fatal_error("First input event must be 'init'"); if (data->supportcaps) { /* Set the suppport preference flags. (Bit of a layering violation, but the flags are simple.) */ if (data->supportcaps->timer) pref_timersupport = TRUE; if (data->supportcaps->hyperlinks) pref_hyperlinksupport = TRUE; if (data->supportcaps->graphics) pref_graphicssupport = TRUE; if (data->supportcaps->graphicswin) pref_graphicswinsupport = TRUE; } /* Copy the metrics into the permanent structure */ *metrics = *data->metrics; data_event_free(data); } /* Initialize things. */ gli_initialize_misc(); gli_initialize_windows(metrics); gli_initialize_events(); data_metrics_free(metrics); inittime = TRUE; if (!glkunix_startup_code(&startdata)) { glk_exit(); } inittime = FALSE; if (gli_debugger) gidebug_announce_cycle(gidebug_cycle_Start); /* Call the program main entry point, and then exit. */ glk_main(); glk_exit(); /* glk_exit() doesn't return, but the compiler may kvetch if main() doesn't seem to return a value. */ return 0; }
static void Fatal(const char *x) { Display(Bottom, "%s\n", x); glk_exit(); }