void love(void) { int n; while (wordtype[++wordnumber] != NOUNS && wordnumber <= wordcount) continue; if (wordtype[wordnumber] == NOUNS) { if ((testbit(location[position].objects, BATHGOD) || testbit(location[position].objects, NORMGOD)) && wordvalue[wordnumber] == NORMGOD) { if (loved) { printf("Loved.\n"); return; } if (godready >= 2) { puts("She cuddles up to you, and her mouth starts to work:\n'That was my sister's amulet. The lovely goddess, Purl, was she. The Empire\ncaptured her just after the Darkness came. My other sister, Vert, was killed\nby the Dark Lord himself. He took her amulet and warped its power.\nYour quest was foretold by my father before he died, but to get the Dark Lord's\namulet you must use cunning and skill. I will leave you my amulet,"); puts("which you may use as you wish. As for me, I am the last goddess of the\nwaters. My father was the Island King, and the rule is rightfully mine.'\n\nShe pulls the throne out into a large bed."); power++; pleasure += 15; ego++; if (card(injuries, NUMOFINJURIES)) { puts("Her kisses revive you; your wounds are healed.\n"); for (n = 0; n < NUMOFINJURIES; n++) injuries[n] = 0; WEIGHT = MAXWEIGHT; CUMBER = MAXCUMBER; } printf("Goddess:\n"); if (!loved) setbit(location[position].objects, MEDALION); loved = 1; ourtime += 10; printf("Loved.\n"); zzz(); return; } else { puts("You wish!"); return; } } if (testbit(location[position].objects, wordvalue[wordnumber])) { if (wordvalue[wordnumber] == NATIVE) { puts("The girl peels off her sarong and indulges you."); power++; pleasure += 5; printf("Girl:\n"); ourtime += 10; printf("Loved.\n"); zzz(); } if (wordvalue[wordnumber] == MAN || wordvalue[wordnumber] == BODY || wordvalue[wordnumber] == ELF || wordvalue[wordnumber] == TIMER) puts("Kinky!"); else puts("It doesn't seem to work."); } else puts("Where's your lover?"); } else puts("It doesn't seem to work."); }
void fileOpenCb(Widget w, XEvent *event, String *params, Cardinal *num_params) { FileWindowRec *fw; FileRec *file; int item; char path[MAXPATHLEN]; String *argv, push_action; if (!(fw = findFileWidget(w, &item))) return; zzz(); file = fw->files[item]; strcpy(path, fw->directory); if (path[strlen(path)-1] != '/') strcat(path, "/"); strcat(path, file->name); if (S_ISDIR(file->stats.st_mode)) { contractPath(path); chFileDir(fw, path); } else if (file->stats.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) { String arguments = XtNewString(file->name); String action = (String) XtMalloc((strlen(path) + 6) * sizeof(char)); strcat(strcpy(action, "exec "), path); argv = makeArgv(action, 1, &arguments); executeApplication(user.shell, fw->directory, argv); XTFREE(action); freeArgv(argv); } else if (file->type) { if (*(push_action = file->type->push_action)) { if (!(strcmp(push_action, "EDIT"))) doEdit(fw->directory, file->name); else if (!(strcmp(push_action, "VIEW"))) doView(fw->directory, file->name); else if (!(strcmp(push_action, "LOAD"))) { zzz(); newApplicationWindow(path, NULL); wakeUp(); } else { argv = (String *) XtMalloc(sizeof(String)); argv[0] = XtNewString(file->name); performAction(fw->shell, file->type->icon_pm.bm, push_action, fw->directory, 1, argv); XTFREE(argv); } } } else doEdit(fw->directory, file->name); wakeUp(); }
void crash(void) { int hurt1, hurt2; fuel--; if (!location[position].flyhere || (TestBit(location[position].objects, LAND) && fuel <= 0)) { if (!location[position].flyhere) puts("You're flying too low. We're going to crash!"); else { puts("You're out of fuel. We'll have to crash land!"); if (!location[position].down) { puts("Your viper strikes the ground and explodes into fiery fragments."); puts("Thick black smoke billows up from the wreckage."); die(0); } position = location[position].down; } notes[LAUNCHED] = 0; SetBit(location[position].objects, CRASH); ourtime += rnd(CYCLE / 4); puts("The viper explodes into the ground and you lose consciousness..."); zzz(); hurt1 = rnd(NUMOFINJURIES - 2) + 2; hurt2 = rnd(NUMOFINJURIES - 2) + 2; injuries[hurt1] = 1; injuries[hurt2] = 1; injuries[0] = 1; /* abrasions */ injuries[1] = 1; /* lacerations */ printf("I'm afraid you have suffered %s and %s.\n", ouch[hurt1], ouch[hurt2]); } }
void executeApplication(char *path, char *directory, char **argv) { int pid; zzz(); XFlush(XtDisplay(toplevel)); if (chdir(directory)) { wakeUp(); sysError("Can't chdir:"); } else if ((pid = fork()) == -1) { wakeUp(); sysError("Can't fork:"); } else { if (!pid) { if (resources.echo_actions) { char **arg; fprintf(stderr, "[%s] %s", directory, path); for (arg = argv+1; *arg; arg++) echoarg(*arg); fprintf(stderr, "\n"); } /* Make sure that child processes don't lock up xfm with keyboard input. This is certainly a kludge and if you know of any better way to do this, please let me know. -ag */ freopen("/dev/null", "r", stdin); execvp(path, argv); perror("Exec failed"); exit(1); } else { sleep(1); wakeUp(); } } }
void displayGizmo(PixelImage* image, Matrix4 m) { int w2 = image->getWidth()/2; int h2 = image->getHeight()/2; Vector3 ooo(0,0,0); Vector3 xxx(50,0,0); Vector3 yyy(0,50,0); Vector3 zzz(0,0,50); ooo *= m; xxx *= m; yyy *= m; zzz *= m; ooo.x += w2; ooo.y = h2-ooo.y; xxx.x += w2; xxx.y = h2-xxx.y; yyy.x += w2; yyy.y = h2-yyy.y; zzz.x += w2; zzz.y = h2-zzz.y; DoubleColor cx = {1, 0, 0, 1}; DoubleColor cy = {0, 1, 0, 1}; DoubleColor cz = {0, 0, 1, 1}; d2d::Line lx; lx.beg = ooo.view(); lx.end = xxx.view(); lx.col = cx; d2d::Line ly; ly.beg = ooo.view(); ly.end = yyy.view(); ly.col = cy; d2d::Line lz; lz.beg = ooo.view(); lz.end = zzz.view(); lz.col = cz; d2d::lineDotsAdapt(image, &lx, 1.0); d2d::lineDotsAdapt(image, &ly, 1.0); d2d::lineDotsAdapt(image, &lz, 1.0); }
int main(int, char**) { bool b; int x = (b ? A(5, 3) : A()).zz() + 55; // int x = b ? A(3).zz() : 1; A(3, 4).zz(); A zzz(3, 7); return 0; }
void newFileWinCb(Widget w, XtPointer client_data, XtPointer call_data) { FileWindowRec *fw = (FileWindowRec *) client_data; zzz(); newFileWindow(fw->directory, fw, NULL); wakeUp(); }
int drive(void) { if (TestBit(location[position].objects, CAR)) { puts("You hop in the car and turn the key. There is a perceptible grating noise,"); puts("and an explosion knocks you unconscious..."); ClearBit(location[position].objects, CAR); SetBit(location[position].objects, CRASH); injuries[5] = injuries[6] = injuries[7] = injuries[8] = 1; ourtime += 15; zzz(); return (0); } else puts("There is nothing to drive here."); return (-1); }
void dirOpenCb(Widget w, XtPointer client_data, XtPointer call_data) { FileWindowRec *fw = (FileWindowRec *) client_data; char path[MAXPATHLEN]; int item; zzz(); XtVaGetValues(fw->form, XmNuserData, (XtPointer) &item, NULL); strcpy(path, fw->directory); if (path[strlen(path)-1] != '/') strcat(path, "/"); strcat(path, fw->files[item]->name); fnexpand(path); contractPath(path); newFileWindow(path, fw, NULL); wakeUp(); }
void xtermCb(Widget w, XtPointer client_data, XtPointer call_data) { FileWindowRec *fw = (FileWindowRec *) client_data; String *argv; zzz(); argv = (String *) XtMalloc(4 * sizeof(String)); argv[0] = user.shell; argv[1] = "-c"; argv[2] = resources.xterm; argv[3] = NULL; executeApplication(user.shell, fw->directory, argv); XTFREE(argv); wakeUp(); }
drink() { register int n; if (testbit(inven,POTION)){ puts("The cool liquid runs down your throat but turns to fire and you choke."); puts("The heat reaches your limbs and tingles your spirit. You feel like falling"); puts("asleep."); clearbit(inven, POTION); WEIGHT = MAXWEIGHT; CUMBER = MAXCUMBER; for (n=0; n < NUMOFINJURIES; n++) injuries[n] = 0; time++; zzz(); } else puts("I'm not thirsty."); }
main() { int a, b; // TITLE PRINT("= = = определение номеров DRAM-банков = = =\n"); PRINT_TITLE; // subTITLE printf(" BLOCK\n SIZE (Kb) - - - n BANK - - -\n"); printf("----!----------------------------------------------------------------------\n"); // циклически выдел¤ем блоки пам¤ти различного размера for(a = STEP_FACTOR; a < MAX_MEM_SIZE; a += STEP_FACTOR) { printf("%04d:",a/K); /* размер затребованной пам¤ти */ for (b = 0; b < N_ITER; b++) printf("\t%x",zzz(a)); /* xx DRAM-банк! */ printf("\n"); } }
void dirPopupCb(Widget w, XtPointer client_data, XtPointer call_data) { FileWindowRec *fw = (FileWindowRec *) client_data; MenuItemRec *menu; if ((menu = fw->dirfieldPopupMenu)) { while (menu->label && menu->object != w) menu++; if (menu->label) { if (resources.newwin_on_dirpopup) { zzz(); newFileWindow(menu->label, fw, NULL); wakeUp(); } else chFileDir(fw, menu->label); } } }
void news(void) { int n; int hurt; if (ourtime > 30 && position < 32) { puts("An explosion of shuddering magnitude splinters bulkheads and"); puts("ruptures the battlestar's hull. You are sucked out into the"); puts("frozen void of space and killed."); die(0); } if (ourtime > 20 && position < 32) puts("Explosions rock the battlestar."); if (ourtime > snooze) { puts("You drop from exhaustion..."); zzz(); } if (ourtime > snooze - 5) puts("You're getting tired."); if (ourtime > (rythmn + CYCLE)) { if (location == nightfile) { convert(TODAY); if (OUTSIDE && ourtime - rythmn - CYCLE < 10) { puts("Dew lit sunbeams stretch out from a watery sunrise and herald the dawn."); puts("You awake from a misty dream-world into stark reality."); puts("It is day."); } } else { convert(TONIGHT); ClearBit(location[POOLS].objects, BATHGOD); if (OUTSIDE && ourtime - rythmn - CYCLE < 10) { puts("The dying sun sinks into the ocean, leaving a blood-stained sunset."); puts("The sky slowly fades from orange to violet to black. A few stars"); puts("flicker on, and it is night."); puts("The world seems completely different at night."); } } rythmn = ourtime - ourtime % CYCLE; } if (!wiz && !tempwiz) if ((TestBit(inven, TALISMAN) || TestBit(wear, TALISMAN)) && (TestBit(inven, MEDALION) || TestBit(wear, MEDALION)) && (TestBit(inven, AMULET) || TestBit(wear, AMULET))) { tempwiz = 1; puts("The three amulets glow and reenforce each other in power.\nYou are now a wizard."); } if (TestBit(location[position].objects, ELF)) { printf("%s\n", objdes[ELF]); fight(ELF, rnd(30)); } if (TestBit(location[position].objects, DARK)) { printf("%s\n", objdes[DARK]); fight(DARK, 100); } if (TestBit(location[position].objects, WOODSMAN)) { printf("%s\n", objdes[WOODSMAN]); fight(WOODSMAN, 50); } switch (position) { case 267: case 257: /* entering a cave */ case 274: case 246: notes[CANTSEE] = 1; break; case 160: case 216: /* leaving a cave */ case 230: case 231: case 232: notes[CANTSEE] = 0; break; } if (TestBit(location[position].objects, GIRL)) meetgirl = 1; if (meetgirl && CYCLE * 1.5 - ourtime < 10) { SetBit(location[GARDEN].objects, GIRLTALK); SetBit(location[GARDEN].objects, LAMPON); SetBit(location[GARDEN].objects, ROPE); } if (position == DOCK && (beenthere[position] || ourtime > CYCLE)) { ClearBit(location[DOCK].objects, GIRL); ClearBit(location[DOCK].objects, MAN); } if (meetgirl && ourtime - CYCLE * 1.5 > 10) { ClearBit(location[GARDEN].objects, GIRLTALK); ClearBit(location[GARDEN].objects, LAMPON); ClearBit(location[GARDEN].objects, ROPE); meetgirl = 0; } if (TestBit(location[position].objects, CYLON)) { puts("Oh my God, you're being shot at by an alien spacecraft!"); printf("The targeting computer says we have %d seconds to attack!\n", ourclock); fflush(stdout); sleep(1); if (!visual()) { hurt = rnd(NUMOFINJURIES); injuries[hurt] = 1; puts("Laser blasts sear the cockpit, and the alien veers off in a victory roll."); puts("The viper shudders under a terrible explosion."); printf("I'm afraid you have suffered %s.\n", ouch[hurt]); } else ClearBit(location[position].objects, CYLON); } if (injuries[SKULL] && injuries[INCISE] && injuries[NECK]) { puts("I'm afraid you have suffered fatal injuries."); die(0); } for (n = 0; n < NUMOFINJURIES; n++) if (injuries[n] == 1) { injuries[n] = 2; if (WEIGHT > 5) WEIGHT -= 5; else WEIGHT = 0; } if (injuries[ARM] == 2) { if (CUMBER > 5) CUMBER -= 5; else CUMBER = 0; injuries[ARM]++; } if (injuries[RIBS] == 2) { if (CUMBER > 2) CUMBER -= 2; else CUMBER = 0; injuries[RIBS]++; } if (injuries[SPINE] == 2) { WEIGHT = 0; injuries[SPINE]++; } if (carrying > WEIGHT || encumber > CUMBER) notes[CANTMOVE] = 1; else notes[CANTMOVE] = 0; }
void updateIconDisplay(void) { struct stat cur; Boolean reread = False; if (dticons_blocked) return; if (resources.check_application_files) if (dticons_readable) reread = stat(resources.dticon_file, &cur) || cur.st_ctime > dticons_stats.st_ctime || cur.st_mtime > dticons_stats.st_mtime; else reread = !stat(resources.dticon_file, &cur); if (reread) { FILE *fp; AppRec *app; char *name, *directory, *fname, *icon, *push_action, *drop_action, *xp, *yp; char *nname, *ndirectory, *nfname, *nicon, *npush_action, *ndrop_action; char s[MAXAPPSTRINGLEN]; int i, j, p, x, y; zzz(); dticons_readable = !stat(resources.dticon_file, &dticons_stats); if (!(fp = fopen(resources.dticon_file, "r"))) { dticons_readable = False; error(getAnyShell(), "Cannot read desktop icons from", resources.dticon_file); i = 0; goto remove; } /* update existing icons/append new ones */ for (i=0; (p = parseIcon(fp, &name, &directory, &fname, &icon, &push_action, &drop_action, &xp, &yp)) > 0; i++) { if ((x = atoi(strparse(s, xp, "\\:"))) < 0) x += winInfo.rootWidth - DTICONWIDTH; if ((y = atoi(strparse(s, yp, "\\:"))) < 0) y += winInfo.rootHeight - DTICONHEIGHT; nname = XtNewString(strparse(s, name, "\\:")); ndirectory = XtNewString(strparse(s, directory, "\\:")); nfname = XtNewString(strparse(s, fname, "\\:")); nicon = XtNewString(strparse(s, icon, "\\:")); npush_action = XtNewString(strparse(s, push_action, "\\:")); ndrop_action = XtNewString(strparse(s, drop_action, "\\:")); if (i < n_dtIcons) { DTIconRec *dticon = dtIcons[i]; app = &dticon->app; if (!(x != dticon->x || y != dticon->y || strcmp(nname, app->name) || strcmp(ndirectory, app->directory) || strcmp(nfname, app->fname) || strcmp(nicon, app->icon) || strcmp(npush_action, app->push_action) || strcmp(ndrop_action, app->drop_action))) { XTFREE(nname); XTFREE(ndirectory); XTFREE(nfname); XTFREE(nicon); XTFREE(npush_action); XTFREE(ndrop_action); continue; } XtDestroyWidget(dticon->app.form); if (dticon->label_mask != None) freePixmap(dticon->label_mask); if (dticon->drop_pixmap != None) freePixmap(dticon->drop_pixmap); freeApplicationResources(&dticon->app); } else { dtIcons = (DTIconRec **) XTREALLOC(dtIcons, (i+1) * sizeof(DTIconRec *)); dtIcons[i] = (DTIconRec *) XtMalloc(sizeof(DTIconRec)); } app = &dtIcons[i]->app; app->name = nname; app->directory = ndirectory; app->fname = nfname; app->icon = nicon; app->push_action = npush_action; app->drop_action = ndrop_action; app->objType = getObjectType(app->push_action); app->remove_file = False; dtIcons[i]->x = x; dtIcons[i]->y = y; readApplicationIcon(getAnyShell(), app, ERR_POPUP); dtIcons[i]->label_mask = None; dtIcons[i]->drop_pixmap = None; dtIcons[i]->moved = False; dtIcons[i]->save = True; displayDTIcon(dtIcons[i]); } remove: /* remove any remaining icons */ for (j = i; j < n_dtIcons; j++) { DTIconRec *dticon = dtIcons[j]; XtDestroyWidget(dticon->shell); freeApplicationResources(&dticon->app); if (dticon->label_mask != None) freePixmap(dticon->label_mask); if (dticon->drop_pixmap != None) freePixmap(dticon->drop_pixmap); XTFREE(dticon); } if (i < n_dtIcons) dtIcons = (DTIconRec **) XTREALLOC(dtIcons, i * sizeof(DTIconRec *)); n_dtIcons = i; wakeUp(); if (dticons_readable && p == -1) error(getAnyShell(), "Error reading desktop icons from", resources.dticon_file); if (dticons_readable && fclose(fp)) sysError(getAnyShell(), "Error reading desktop icons:"); } }
ControllerThread::ControllerThread(PSerialChannel *_serial, Resources * _resources, PConfig *_config) : PThread(10000, NoAutoDeleteThread), queue() { pserial = _serial; resources = _resources; config = _config; analogControls = (config->GetString("Gamepad", "AnalogControl", "")).ToUpper().Tokenise(",", PFalse); PTRACE(2, "Constructing instance for controller"); for(int i = 0; i < 256; i++) { actionQueuePool[i] = new PIntArray(); }; queue.Open(10000); queue.SetReadTimeout(0); // timeout 0 ms queue.SetWriteTimeout(0); // timeout 0 ms timeout = 100; retryLimit = 5; fReady = PFalse; maximumOffset = config->GetInteger("Events", "maximumOffset", 200); maximumDelay = config->GetInteger("Events", "maximumOffset", 10); for (PINDEX i = 0; i < 10; i++) { calibrationTable[i] = new PIntArray; }; for (PINDEX i = 0; i < analogControls.GetSize(); i++) { PStringStream summary; // summary string int summaryN = -100000; // last value in calibrationTable PString calibrationValuesName("Axis"); calibrationValuesName += analogControls[i]; calibrationValuesName += "Motion"; PStringArray calibrationValues = (config->GetString("Gamepad", calibrationValuesName, "")).ToUpper().Tokenise(";", PFalse); if (calibrationValues.GetSize() == 0) { // push linear sequence for (PINDEX j = 0; j < POTENTIOMETER_SCALE; j++) { // from -100.00% to +100.00% we have POTENTIOMETER_SCALE values int min = ((float)20000/POTENTIOMETER_SCALE)*j; int max = ((float)20000/POTENTIOMETER_SCALE)*(j+1); for (PINDEX k = min; k <= max; k++) { // overwrite last value PIntArray *table = calibrationTable[i]; table->SetAt(k, j); }; }; } else { bool redo; do { int previous = 0; int current = 0; int next = 0; redo = PFalse; for (PINDEX j = 0; j < POTENTIOMETER_SCALE; j++) { previous = current; current = calibrationValues[j].AsInteger(); next = calibrationValues[j+1].AsInteger(); if (previous == 20000 && current == 20000) { break; }; if (current > next) { if (next != 0 && next != 10000) { PTRACE(1, "calibration error for axis " << analogControls[i] << " value: " << calibrationValues[j] << " previous:" << previous << " current: " << current << " next: " << next); redo = PTrue; calibrationValues[j] = PString(next); calibrationValues[j+1] = PString(current); break; } else { break; }; }; // set range for (int k = (current+previous)/2; k<=(next+current/2); k++) { PIntArray *table = calibrationTable[i]; table->SetAt(k, j); }; }; } while(redo); // fix head and tail int calibrationMinimum = calibrationTable[i]->GetAt(0)-1 > 0 ? calibrationTable[i]->GetAt(0)-1 : 0; calibrationTable[i]->SetAt(0, calibrationMinimum); int calibrationMaximum = calibrationTable[i]->GetAt(20000)+1 < POTENTIOMETER_SCALE ? calibrationTable[i]->GetAt(20000)+1 : POTENTIOMETER_SCALE-1; calibrationTable[i]->SetAt(20000, calibrationMaximum); }; for(PINDEX j = 0; j<= 20000; j++) { if (summaryN < calibrationTable[i]->GetAt(j)) { summaryN = calibrationTable[i]->GetAt(j); summary << " [" << j << "]:" << calibrationTable[i]->GetAt(j); }; }; PTRACE(4, "ControllerThread\tcalibration summary for '"<< analogControls[i] << "'" << summary); }; // prepare game table for (PINDEX i = 0; i < 10; i++) { gameTable[i] = new PIntArray; }; resetGameTable(); PString zzz("mw2x.z"); loadGameTableT(zzz); // start Resume(); }
void editFileMonCb(Widget w, XtPointer client_data, XtPointer calldata) { zzz(); doEdit(resources.appcfg_path, resources.mon_file); wakeUp(); }
void newAppWinCb(Widget w, XtPointer client_data, XtPointer call_data) { zzz(); newApplicationWindow(NULL, NULL); wakeUp(); }
void moveFilesProc(XtPointer fsel, int conf) { SelFileNamesRec *fnames = (SelFileNamesRec *) fsel; struct stat tostats, tolstats, frstats; char from[MAXPATHLEN], to[MAXPATHLEN]; String name, cwd; String op_name, from_err, to_err; size_t toend, fromend; int devto, devfrom, deverr = -1, i, perm, res; Boolean is_dir, is_link; if (conf != YES || !fnames->op) { freeSelFiles(fnames); return; } if (chdir(fnames->directory)) { sysError(fnames->shell, "System error:"); freeSelFiles(fnames); return; } chdir(user.home); switch (fnames->op) { case COPY: op_name = "Copy:"; from_err = "Error copying"; to_err = "Error copying to"; break; case MOVE: op_name = "Move:"; from_err = "Error moving"; to_err = "Error moving to"; break; default: /* i.e. LINK */ op_name = "Link:"; from_err = "Error creating symlink to"; to_err = "Error creating symlink in"; } if (fnames->target[0] != '/' && fnames->target[0] != '~' && fnames->target != 0) { strcpy(to, fnames->directory); if (to[strlen(to)-1] != '/') strcat(to, "/"); } else to[0] = 0; strcat(to, fnames->target); fnexpand(to); if (!(cwd = absolutePath(to))) { error(fnames->shell, no_target, to); freeSelFiles(fnames); return; } strcpy(to, cwd); XTFREE(cwd); fromend = strlen(strcpy(from, fnames->directory)); if (from[fromend-1] != '/') { from[fromend++] = '/'; from[fromend] = 0; } devfrom = findDev(from); if (mountDev(devto = findDev(to), False)) deverr = devto; else if (mountDev(devfrom, False)) deverr = devfrom; if (deverr != -1) { error(fnames->shell, "Cannot mount device on", mntable.devices[deverr].def_mpoint); umountDev(devto, False); freeSelFiles(fnames); return; } if (!(stat(to, &tostats)) && S_ISDIR(tostats.st_mode)) { if (chdir(to) || !(perm = permission(&tostats, P_WRITE))) { chdir(user.home); if (!perm) error(fnames->shell, "You have no write permission for ", to); else sysError(fnames->shell, "System error:"); umountDev(devto, False); umountDev(devfrom, False); freeSelFiles(fnames); return; } chdir(user.home); fnames->dirtarget = True; toend = strlen(to); if (to[toend-1] != '/') { to[toend++] = '/'; to[toend] = 0; } } else if (fnames->n_sel == 1) fnames->dirtarget = False; else { error(fnames->shell, op_name, "Target for multiple files must be a folder"); umountDev(devto, False); umountDev(devfrom, False); freeSelFiles(fnames); return; } if (!fnames->first) zzz(); XTFREE(fnames->target); fnames->target = XtNewString(to); for (i = fnames->first; i < fnames->n_sel; i++) { name = fnames->names[i]; if (fnames->op != LINK && (!strcmp(name, ".") || !strcmp(name, ".."))) { error(fnames->shell, "Cannot move or copy . or ..", NULL); continue; } strcpy(from+fromend, name); if (fnames->dirtarget) { if (fnames->op != LINK && prefix(from, to)) { String err_str, format = "Cannot move or copy %s to"; err_str = (String) XtMalloc((strlen(format) + strlen(from)) * sizeof(char)); sprintf(err_str, format, from); error(fnames->shell, err_str, to); XTFREE(err_str); umountDev(devto, False); umountDev(devfrom, False); freeSelFiles(fnames); wakeUp(); return; } strcpy(to+toend, name); } if (!(lstat(to, &tolstats))) { fnames->first = i; is_dir = False; if (!(stat(to, &tostats))) { if (S_ISDIR(tostats.st_mode)) is_dir = True; if (!stat(from, &frstats) && tostats.st_ino == frstats.st_ino) { error(fnames->shell, op_name, "Source and destination are identical"); umountDev(devto, False); umountDev(devfrom, False); freeSelFiles(fnames); wakeUp(); return; } } if (S_ISLNK(tolstats.st_mode)) is_link = True; else is_link = False; if (fnames->conf_ovwr || (is_dir && (!is_link || fnames->op == COPY) && resources.confirm_delete_folder)) overwriteDialog(fnames, to, (fnames->op == COPY && is_dir && (lstat(from, &frstats) || !S_ISDIR(frstats.st_mode)))? "File copy:" : op_name, is_dir && (!is_link || fnames->op == COPY)); else overwriteProc(fsel, YES); umountDev(devto, False); umountDev(devfrom, False); return; } switch (fnames->op) { case COPY: rcopy(from, to, False); res = 0; break; case MOVE: res = movefile(from, to); break; default: res = makeLink(from, to); } if (res) { if (opError(fnames->shell, from_err, name) != YES) break; } else fnames->update = True; } umountDev(devto, False); umountDev(devfrom, False); if (fnames->update) { if (fnames->op == COPY) intUpdate(CHECK_DIR); /* Check for new subdirectories */ if (fnames->op == MOVE) markForUpdate(fnames->directory, CHECK_FILES); markForUpdate(to, RESHOW); if (fnames->op != COPY) intUpdate(CHECK_DIR); } freeSelFiles(fnames); wakeUp(); }
int cypher(void) { int n; int junk; int lflag; char buffer[10]; lflag = -1; while (wordtype[wordnumber] == ADJS) wordnumber++; while (wordnumber <= wordcount) { switch (wordvalue[wordnumber]) { case UP: if (location[position].access || wiz || tempwiz) { if (!location[position].access) puts("Zap! A gust of wind lifts you up."); if (!battlestar_move(location[position].up, AHEAD)) return (-1); } else { puts("There is no way up"); return (-1); } lflag = 0; break; case DOWN: if (!battlestar_move(location[position].down, AHEAD)) return (-1); lflag = 0; break; case LEFT: if (!battlestar_move(left, LEFT)) return (-1); lflag = 0; break; case RIGHT: if (!battlestar_move(right, RIGHT)) return (-1); lflag = 0; break; case AHEAD: if (!battlestar_move(ahead, AHEAD)) return (-1); lflag = 0; break; case BACK: if (!battlestar_move(back, BACK)) return (-1); lflag = 0; break; case SHOOT: if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) { for (n = 0; n < NUMOFOBJECTS; n++) if (testbit(location[position].objects, n) && objsht[n]) { wordvalue[wordnumber + 1] = n; wordnumber = shoot(); } wordnumber++; wordnumber++; } else shoot(); break; case TAKE: if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) { for (n = 0; n < NUMOFOBJECTS; n++) if (testbit(location[position].objects, n) && objsht[n]) { wordvalue[wordnumber + 1] = n; wordnumber = take(location[position].objects); } wordnumber++; wordnumber++; } else take(location[position].objects); break; case DROP: if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) { for (n = 0; n < NUMOFOBJECTS; n++) if (testbit(inven, n)) { wordvalue[wordnumber + 1] = n; wordnumber = drop("Dropped"); } wordnumber++; wordnumber++; } else drop("Dropped"); break; case KICK: case THROW: if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) { for (n = 0; n < NUMOFOBJECTS; n++) { if ((testbit(inven, n) || testbit(location[position].objects, n)) && objsht[n]) { wordvalue[wordnumber + 1] = n; wordnumber = throw(wordvalue[wordnumber] == KICK ? "Kicked" : "Thrown"); } } wordnumber += 2; } else throw(wordvalue[wordnumber] == KICK ? "Kicked" : "Thrown"); break; case TAKEOFF: if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) { for (n = 0; n < NUMOFOBJECTS; n++) if (testbit(wear, n)) { wordvalue[wordnumber + 1] = n; wordnumber = takeoff(); } wordnumber += 2; } else takeoff(); break; case DRAW: if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) { for (n = 0; n < NUMOFOBJECTS; n++) if (testbit(wear, n)) { wordvalue[wordnumber + 1] = n; wordnumber = draw(); } wordnumber += 2; } else draw(); break; case PUTON: if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) { for (n = 0; n < NUMOFOBJECTS; n++) if (testbit(location[position].objects, n) && objsht[n]) { wordvalue[wordnumber + 1] = n; wordnumber = puton(); } wordnumber += 2; } else puton(); break; case WEARIT: if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) { for (n = 0; n < NUMOFOBJECTS; n++) if (testbit(inven, n)) { wordvalue[wordnumber + 1] = n; wordnumber = wearit(); } wordnumber += 2; } else wearit(); break; case EAT: if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) { for (n = 0; n < NUMOFOBJECTS; n++) if (testbit(inven, n)) { wordvalue[wordnumber + 1] = n; wordnumber = eat(); } wordnumber += 2; } else eat(); break; case PUT: put(); break; case INVEN: if (ucard(inven)) { puts("You are holding:\n"); for (n = 0; n < NUMOFOBJECTS; n++) if (testbit(inven, n)) printf("\t%s\n", objsht[n]); printf("\n= %d kilogram%s (%d%%)\n", carrying, (carrying == 1 ? "." : "s."), (WEIGHT ? carrying * 100 / WEIGHT : -1)); printf("Your arms are %d%% full.\n", encumber * 100 / CUMBER); } else puts("You aren't carrying anything."); if (ucard(wear)) { puts("\nYou are wearing:\n"); for (n = 0; n < NUMOFOBJECTS; n++) if (testbit(wear, n)) printf("\t%s\n", objsht[n]); } else puts("\nYou are stark naked."); if (card(injuries, NUMOFINJURIES)) { puts("\nYou have suffered:\n"); for (n = 0; n < NUMOFINJURIES; n++) if (injuries[n]) printf("\t%s\n", ouch[n]); printf("\nYou can still carry up to %d kilogram%s\n", WEIGHT, (WEIGHT == 1 ? "." : "s.")); } else puts("\nYou are in perfect health."); break; case USE: lflag = use(); break; case LOOK: if (!notes[CANTSEE] || testbit(inven, LAMPON) || testbit(location[position].objects, LAMPON) || matchlight) { beenthere[position] = 2; writedes(); printobjs(); if (matchlight) { puts("\nYour match splutters out."); matchlight = 0; } } else puts("I can't see anything."); return (-1); break; case SU: if (wiz || tempwiz) { printf("\nRoom (was %d) = ", position); fgets(buffer, 10, stdin); if (*buffer != '\n') sscanf(buffer, "%d", &position); printf("Time (was %d) = ", gtime); fgets(buffer, 10, stdin); if (*buffer != '\n') sscanf(buffer, "%d", >ime); printf("Fuel (was %d) = ", fuel); fgets(buffer, 10, stdin); if (*buffer != '\n') sscanf(buffer, "%d", &fuel); printf("Torps (was %d) = ", torps); fgets(buffer, 10, stdin); if (*buffer != '\n') sscanf(buffer, "%d", &torps); printf("CUMBER (was %d) = ", CUMBER); fgets(buffer, 10, stdin); if (*buffer != '\n') sscanf(buffer, "%d", &CUMBER); printf("WEIGHT (was %d) = ", WEIGHT); fgets(buffer, 10, stdin); if (*buffer != '\n') sscanf(buffer, "%d", &WEIGHT); printf("Clock (was %d) = ", gclock); fgets(buffer, 10, stdin); if (*buffer != '\n') sscanf(buffer, "%d", &gclock); printf("Wizard (was %d, %d) = ", wiz, tempwiz); fgets(buffer, 10, stdin); if (*buffer != '\n') { sscanf(buffer, "%d", &junk); if (!junk) tempwiz = wiz = 0; } printf("\nDONE.\n"); return (0); } else puts("You aren't a wizard."); break; case SCORE: printf("\tPLEASURE\tPOWER\t\tEGO\n"); printf("\t%3d\t\t%3d\t\t%3d\n\n", pleasure, power, ego); printf("This gives you the rating of %s in %d turns.\n", rate(), gtime); printf("You have visited %d out of %d rooms this run (%d%%).\n", card(beenthere, NUMOFROOMS), NUMOFROOMS, card(beenthere, NUMOFROOMS) * 100 / NUMOFROOMS); break; case KNIFE: case KILL: murder(); break; case UNDRESS: case RAVAGE: ravage(); break; case SAVE: save(); break; case FOLLOW: lflag = follow(); break; case GIVE: give(); break; case KISS: kiss(); break; case LOVE: love(); break; case RIDE: lflag = ride(); break; case DRIVE: lflag = drive(); break; case LIGHT: light(); break; case LAUNCH: if (!launch()) return (-1); else lflag = 0; break; case LANDIT: if (!land()) return (-1); else lflag = 0; break; case TIME: chime(); break; case SLEEP: zzz(); break; case DIG: dig(); break; case JUMP: lflag = jump(); break; case BURY: bury(); break; case SWIM: puts("Surf's up!"); break; case DRINK: drink(); break; case QUIT: die(0); default: puts("How's that?"); return (-1); break; } if (wordnumber < wordcount && *words[wordnumber++] == ',') continue; else return (lflag); } return (lflag); }
/* returns 0 if error or no more commands to do, * 1 if there are more commands remaining on the current input line */ int cypher(void) { int n; int junk; int lflag = -1; char *filename, *rfilename; size_t filename_len; while (wordnumber <= wordcount) { if (wordtype[wordnumber] != VERB && !(wordtype[wordnumber] == OBJECT && wordvalue[wordnumber] == KNIFE)) { printf("%s: How's that?\n", (wordnumber == wordcount) ? words[wordnumber - 1] : words[wordnumber]); return (0); } switch (wordvalue[wordnumber]) { case AUXVERB: /* Take the following word as the verb */ wordnumber++; return(cypher()); break; case UP: if (location[position].access || wiz || tempwiz) { if (!location[position].access) puts("Zap! A gust of wind lifts you up."); if (!moveplayer(location[position].up, AHEAD)) return (0); } else { puts("There is no way up."); return (0); } lflag = 0; break; case DOWN: if (!moveplayer(location[position].down, AHEAD)) return (0); lflag = 0; break; case LEFT: if (!moveplayer(left, LEFT)) return (0); lflag = 0; break; case RIGHT: if (!moveplayer(right, RIGHT)) return (0); lflag = 0; break; case AHEAD: if (!moveplayer(ahead, AHEAD)) return (0); lflag = 0; break; case BACK: if (!moveplayer(back, BACK)) return (0); lflag = 0; break; case SHOOT: verb_with_all(location[position].objects, OBJ_PERSON, shoot, "shoot at"); break; case TAKE: if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) { int things; things = 0; for (n = 0; n < NUMOFOBJECTS; n++) if (TestBit(location[position].objects, n) && objsht[n]) { things++; wordvalue[wordnumber + 1] = n; /* Some objects (type NOUNS) have special treatment in take(). For these * we must set the type to NOUNS. However for SWORD and BODY all it does * is find which of many objects is meant, so we need do nothing here. * BATHGOD must become NORMGOD as well. NOUNS with no special case must be * included here to get the right error. DOOR cannot occur as an object so * need not be included. */ switch (n) { case BATHGOD: wordvalue[wordnumber + 1] = NORMGOD; /* FALLTHROUGH */ case NORMGOD: case AMULET: case MEDALION: case TALISMAN: case MAN: case TIMER: case NATIVE: wordtype[wordnumber + 1] = NOUNS; break; default: wordtype[wordnumber + 1] = OBJECT; } wordnumber = take(location[position].objects); wordnumber += 2; } if (!things) puts("Nothing to take!"); } else take(location[position].objects); break; case DROP: if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) { int things; things = 0; for (n = 0; n < NUMOFOBJECTS; n++) if (TestBit(inven, n)) { things++; wordvalue[wordnumber + 1] = n; wordnumber = drop("Dropped"); } wordnumber++; wordnumber++; if (!things) puts("Nothing to drop!"); } else drop("Dropped"); break; case KICK: case THROW: if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) { int things, wv; things = 0; wv = wordvalue[wordnumber]; for (n = 0; n < NUMOFOBJECTS; n++) if (TestBit(inven, n) || (TestBit(location[position].objects, n) && objsht[n])) { things++; wordvalue[wordnumber + 1] = n; wordnumber = throw(wordvalue[wordnumber] == KICK ? "Kicked" : "Thrown"); } wordnumber += 2; if (!things) printf("Nothing to %s!\n", wv == KICK ? "kick" : "throw"); } else throw(wordvalue[wordnumber] == KICK ? "Kicked" : "Thrown"); break; case TAKEOFF: verb_with_all(wear, 0, takeoff, "take off"); break; case DRAW: verb_with_all(wear, 0, draw, "draw"); break; case PUTON: verb_with_all(location[position].objects, 0, puton, "put on"); break; case WEARIT: verb_with_all(inven, 0, wearit, "wear"); break; case EAT: verb_with_all(inven, 0, eat, "eat"); break; case PUT: put(); break; case INVEN: if (ucard(inven)) { puts("You are holding:\n"); for (n = 0; n < NUMOFOBJECTS; n++) if (TestBit(inven, n)) printf("\t%s\n", objsht[n]); printf("\n= %d kilogram%s ", carrying, (carrying == 1 ? "." : "s.")); if (WEIGHT) printf("(%d%%)\n", carrying * 100 / WEIGHT); else printf("(can't lift any weight%s)\n", (carrying ? " or move with what you have" : "")); if (CUMBER) printf("Your arms are %d%% full.\n", encumber * 100 / CUMBER); else printf("You can't pick anything up.\n"); } else puts("You aren't carrying anything."); if (ucard(wear)) { puts("\nYou are wearing:\n"); for (n = 0; n < NUMOFOBJECTS; n++) if (TestBit(wear, n)) printf("\t%s\n", objsht[n]); } else puts("\nYou are stark naked."); if (card(injuries, NUMOFINJURIES)) { puts("\nYou have suffered:\n"); for (n = 0; n < NUMOFINJURIES; n++) if (injuries[n]) printf("\t%s\n", ouch[n]); printf("\nYou can still carry up to %d kilogram%s\n", WEIGHT, (WEIGHT == 1 ? "." : "s.")); } else puts("\nYou are in perfect health."); break; case USE: lflag = use(); break; case OPEN: dooropen(); break; case LOOK: if (!notes[CANTSEE] || TestBit(inven, LAMPON) || TestBit(location[position].objects, LAMPON) || matchlight) { beenthere[position] = 2; writedes(); printobjs(); if (matchlight) { puts("\nYour match splutters out."); matchlight = 0; } } else puts("I can't see anything."); return (0); /* No commands after a look */ break; case SU: if (wiz || tempwiz) { getnum(&position, "\nRoom (was %d) = ", position); getnum(&ourtime, "Time (was %d) = ", ourtime); getnum(&fuel, "Fuel (was %d) = ", fuel); getnum(&torps, "Torps (was %d) = ", torps); getnum(&CUMBER, "CUMBER (was %d) = ", CUMBER); getnum(&WEIGHT, "WEIGHT (was %d) = ", WEIGHT); getnum(&ourclock, "Clock (was %d) = ", ourclock); if (getnum(&junk, "Wizard (was %d, %d) = ", wiz, tempwiz) != -1 && !junk) tempwiz = wiz = 0; printf("\nDONE.\n"); return (0); /* No commands after a SU */ } else puts("You aren't a wizard."); break; case SCORE: printf("\tPLEASURE\tPOWER\t\tEGO\n"); printf("\t%3d\t\t%3d\t\t%3d\n\n", pleasure, power, ego); printf("This gives you the rating of %s in %d turns.\n", rate(), ourtime); printf("You have visited %d out of %d rooms this run (%d%%).\n", card(beenthere, NUMOFROOMS), NUMOFROOMS, card(beenthere, NUMOFROOMS) * 100 / NUMOFROOMS); break; /* case KNIFE: */ case KILL: murder(); break; case UNDRESS: undress(); break; case RAVAGE: ravage(); break; case SAVE: printf("\nSave file name (default %s): ", DEFAULT_SAVE_FILE); filename = fgetln(stdin, &filename_len); if (filename_len == 0 || (filename_len == 1 && filename[0] == '\n')) rfilename = save_file_name(DEFAULT_SAVE_FILE, strlen(DEFAULT_SAVE_FILE)); else { if (filename[filename_len - 1] == '\n') filename_len--; rfilename = save_file_name(filename, filename_len); } save(rfilename); free(rfilename); break; case VERBOSE: verbose = 1; printf("[Maximum verbosity]\n"); break; case BRIEF: verbose = 0; printf("[Standard verbosity]\n"); break; case FOLLOW: lflag = follow(); break; case GIVE: give(); break; case KISS: kiss(); break; case LOVE: love(); break; case RIDE: lflag = ride(); break; case DRIVE: lflag = drive(); break; case LIGHT: light(); break; case LAUNCH: if (!launch()) return (0); else lflag = 0; break; case LANDIT: if (!land()) return (0); else lflag = 0; break; case TIME: chime(); break; case SLEEP: zzz(); break; case DIG: dig(); break; case JUMP: lflag = jump(); break; case BURY: bury(); break; case SWIM: puts("Surf's up!"); break; case DRINK: drink(); break; case QUIT: die(0); default: puts("How's that?"); return (0); break; } if (!lflag) newlocation(); if (wordnumber < wordcount && !stop_cypher && (*words[wordnumber] == ',' || *words[wordnumber] == '.')) { wordnumber++; return (1); } else return (0); } return (0); }