status_t ArpMultiDir::GetNextRef(entry_ref* ref) { status_t ret = B_OK; if( cur_dirs_index < 0 ) ret = next_dir(); if( ret != B_OK ) return ret; do { if( ret == ENOENT ) ret = next_dir(); if( ret != B_NO_ERROR ) return ret; ret = inherited::GetNextRef(ref); } while( ret == ENOENT && inherited::InitCheck() == B_NO_ERROR ); return ret; }
status_t ArpMultiDir::GetNextEntry(BEntry* entry, bool traverse) { status_t ret = B_OK; if( cur_dirs_index < 0 ) ret = next_dir(); if( ret != B_OK ) return ret; do { if( ret == ENOENT ) ret = next_dir(); if( ret != B_NO_ERROR ) return ret; ret = inherited::GetNextEntry(entry,traverse); } while( ret == ENOENT && inherited::InitCheck() == B_NO_ERROR ); return ret; }
int32 ArpMultiDir::GetNextDirents(struct dirent *buf, size_t length, int32 count) { int32 outcount = 0; status_t ret = B_NO_ERROR; if( cur_dirs_index < 0 ) if( next_dir() != B_OK ) return 0; do { if( ret == ENOENT ) ret = next_dir(); if( ret != B_NO_ERROR ) return outcount; outcount = inherited::GetNextDirents(buf,length,count); } while( outcount == 0 && inherited::InitCheck() == B_NO_ERROR ); return outcount; }
anyrequests () #endif { long lastdir = -1; char * name; /* * This routine walks through the requests (secure) * directory looking for files, descending one level * into each sub-directory, if any. Finding at least * one file means that a request is queued. */ while ((name = next_dir(Lp_Requests, &lastdir))) { long lastfile = -1; char * subdir; if (!(subdir = makepath(Lp_Requests, name, (char *)0))) return (1); /* err on safe side */ if (next_file(subdir, &lastfile)) { Free (subdir); return (1); } Free (subdir); } return (0); }
int solve() { int x, y, s = 0, t, pc = 0; init_pos(&x, &y); memset(idx, -1, sizeof(idx)); pos[0] = x*MAXN+y; idx[x][y][0] = 0; for(;;) { t = next_dir(pc++); if(pc == prog_len) pc = 0; int x1 = x+dx[t], y1 = y+dy[t]; if(grid[x1][y1] != '#') { x = x1, y = y1; pos[++s] = x*MAXN+y; } //printf("haha %d %d %d %d\n", x, y, pc, s); if(idx[x][y][pc] >= 0) break; idx[x][y][pc] = s; } if(s == idx[x][y][pc]) return 1; return find_period(s-idx[x][y][pc], idx[x][y][pc], s-1); }
int ep (int argc, char *argvp[]) { u32 key; dir_s d; int rc; for (key = 0; key != 0xffffffffUL;) { rc = next_dir(key, &key, &d); if (rc) break; printf("%u %8x %x %s\n", key-1, d.d_ino, d.d_type, d.d_name); } return 0; }
static int skip_disk(T*& ptr) { int result = dk_noflags; if (!*ptr) return result; if (ptr[0] == '\\' && ptr[1] == '\\') { result |= dk_unc|dk_fromroot; ptr += 2; if (next_dir(ptr) != dt_dir) return dk_error; // has no host name if (next_dir(ptr) != dt_dir) return dk_error; // has no share name } else { if (*ptr && *(ptr+1) == ':') { result |= dk_hasdrive; ptr += 2; } if (*ptr == '\\' || *ptr == '/') { ptr++; result |= dk_fromroot; } } return result; }
static int remap_data_next(ft_data *ftd, int isign){ int dirold, dirnew, index; dirold = ftd->dir; dirnew = next_dir(dirold, isign); index = remap_dir[dirold][dirnew]; if(index == NODIR){ printf("fourier_ftdata_alldir: Bad map %d to %d\n",dirold, dirnew); terminate(1); } remap_data(index, ftd); ftd->dir = dirnew; return dirnew; }
int apply (int (*fn)(char *, void *), void *data) { u32 key; dir_s d; int rc; for (key = 0;;) { if (next_dir(key, &key, &d) != 0) { break; } rc = fn(d.d_name, data); if (rc) { return rc; } } return 0; }
int expand (char *p, int (fn)(char *)) { u32 key; dir_s d; int rc; for (key = 0;;) { rc = next_dir(key, &key, &d); if (rc) break; if (isMatch(p, d.d_name)) { rc = fn(d.d_name); if (rc) { return rc; } } } return 0; }
int correctpath(char *cpath, const char *path) { if (!path || !*path) { *cpath = 0; return 1; } char *ptr = (char*)path; char *cptr = cpath; int counter = 0; while (*ptr) { char c = *ptr; if (c == '/') c = '\\'; if (c == '\\') counter++; else counter = 0; if (counter <= 1) { *cptr = c; cptr++; } ptr++; } *cptr = 0; // replace '/' by '\' int dk = skip_disk(cpath); if (dk == dk_error) return 0; char *ptr1 = ptr = cpath; int level = 0; while (*ptr) { switch (next_dir(ptr)) { case dt_dir: level++; break; case dt_empty: memmove(ptr1, ptr, strlen(ptr)+1); ptr = ptr1; break; case dt_up: level--; if (level >= 0) { *--ptr1 = 0; ptr1 = strrchr(cpath, '\\'); if (!ptr1) ptr1 = cpath; else ptr1++; memmove(ptr1, ptr, strlen(ptr)+1); ptr = ptr1; break; } else if (level == -1 && (dk & dk_hasdrive)) { if (*ptr && *(ptr+1) == ':' && *(cpath-2) == ':') { memmove(cpath-3, ptr, strlen(ptr)+1); return 1; } } if (dk&dk_fromroot) return 0; break; case dt_error: default: return 0; } ptr1 = ptr; } if ((ptr > cpath || ptr == cpath && dk&dk_unc) && *(ptr-1) == '\\') *(ptr-1) = 0; return 1; }
static void term_handle_key(mpg123_handle *fr, out123_handle *ao, char val) { debug1("term_handle_key: %c", val); switch(tolower(val)) { case MPG123_BACK_KEY: out123_pause(ao); out123_drop(ao); if(paused) pause_cycle=(int)(LOOP_CYCLES/mpg123_tpf(fr)); if(mpg123_seek_frame(fr, 0, SEEK_SET) < 0) error1("Seek to begin failed: %s", mpg123_strerror(fr)); framenum=0; break; case MPG123_NEXT_KEY: out123_pause(ao); out123_drop(ao); next_track(); break; case MPG123_NEXT_DIR_KEY: out123_pause(ao); out123_drop(ao); next_dir(); break; case MPG123_QUIT_KEY: debug("QUIT"); if(stopped) { stopped = 0; out123_pause(ao); /* no chance for annoying underrun warnings */ out123_drop(ao); } set_intflag(); offset = 0; break; case MPG123_PAUSE_KEY: paused=1-paused; out123_pause(ao); /* underrun awareness */ out123_drop(ao); if(paused) { /* Not really sure if that is what is wanted This jumps in audio output, but has direct reaction to pausing loop. */ out123_param_float(ao, OUT123_PRELOAD, 0.); pause_recycle(fr); } else out123_param_float(ao, OUT123_PRELOAD, param.preload); if(stopped) stopped=0; if(param.verbose) print_stat(fr, 0, ao); else fprintf(stderr, "%s", (paused) ? MPG123_PAUSED_STRING : MPG123_EMPTY_STRING); break; case MPG123_STOP_KEY: case ' ': /* TODO: Verify/ensure that there is no "chirp from the past" when seeking while stopped. */ stopped=1-stopped; if(paused) { paused=0; offset -= pause_cycle; } if(stopped) out123_pause(ao); else { if(offset) /* If position changed, old is outdated. */ out123_drop(ao); /* No out123_continue(), that's triggered by out123_play(). */ } if(param.verbose) print_stat(fr, 0, ao); else fprintf(stderr, "%s", (stopped) ? MPG123_STOPPED_STRING : MPG123_EMPTY_STRING); break; case MPG123_FINE_REWIND_KEY: seekmode(fr, ao); offset--; break; case MPG123_FINE_FORWARD_KEY: seekmode(fr, ao); offset++; break; case MPG123_REWIND_KEY: seekmode(fr, ao); offset-=10; break; case MPG123_FORWARD_KEY: seekmode(fr, ao); offset+=10; break; case MPG123_FAST_REWIND_KEY: seekmode(fr, ao); offset-=50; break; case MPG123_FAST_FORWARD_KEY: seekmode(fr, ao); offset+=50; break; case MPG123_VOL_UP_KEY: mpg123_volume_change(fr, 0.02); break; case MPG123_VOL_DOWN_KEY: mpg123_volume_change(fr, -0.02); break; case MPG123_PITCH_UP_KEY: case MPG123_PITCH_BUP_KEY: case MPG123_PITCH_DOWN_KEY: case MPG123_PITCH_BDOWN_KEY: case MPG123_PITCH_ZERO_KEY: { double new_pitch = param.pitch; switch(val) /* Not tolower here! */ { case MPG123_PITCH_UP_KEY: new_pitch += MPG123_PITCH_VAL; break; case MPG123_PITCH_BUP_KEY: new_pitch += MPG123_PITCH_BVAL; break; case MPG123_PITCH_DOWN_KEY: new_pitch -= MPG123_PITCH_VAL; break; case MPG123_PITCH_BDOWN_KEY: new_pitch -= MPG123_PITCH_BVAL; break; case MPG123_PITCH_ZERO_KEY: new_pitch = 0.0; break; } set_pitch(fr, ao, new_pitch); fprintf(stderr, "New pitch: %f\n", param.pitch); } break; case MPG123_VERBOSE_KEY: param.verbose++; if(param.verbose > VERBOSE_MAX) { param.verbose = 0; clear_stat(); } mpg123_param(fr, MPG123_VERBOSE, param.verbose, 0); break; case MPG123_RVA_KEY: if(++param.rva > MPG123_RVA_MAX) param.rva = 0; if(param.verbose) fprintf(stderr, "\n"); mpg123_param(fr, MPG123_RVA, param.rva, 0); mpg123_volume_change(fr, 0.); break; case MPG123_PREV_KEY: out123_pause(ao); out123_drop(ao); prev_track(); break; case MPG123_PREV_DIR_KEY: out123_pause(ao); out123_drop(ao); prev_dir(); break; case MPG123_PLAYLIST_KEY: fprintf(stderr, "%s\nPlaylist (\">\" indicates current track):\n", param.verbose ? "\n" : ""); print_playlist(stderr, 1); fprintf(stderr, "\n"); break; case MPG123_TAG_KEY: fprintf(stderr, "%s\n", param.verbose ? "\n" : ""); print_id3_tag(fr, param.long_id3, stderr); fprintf(stderr, "\n"); break; case MPG123_MPEG_KEY: if(param.verbose) print_stat(fr,0,ao); /* Make sure that we are talking about the correct frame. */ fprintf(stderr, "\n"); if(param.verbose > 1) print_header(fr); else print_header_compact(fr); fprintf(stderr, "\n"); break; case MPG123_HELP_KEY: { /* This is more than the one-liner before, but it's less spaghetti. */ int i; fprintf(stderr,"\n\n -= terminal control keys =-\n"); for(i=0; i<(sizeof(term_help)/sizeof(struct keydef)); ++i) { if(term_help[i].key2) fprintf(stderr, "[%c] or [%c]", term_help[i].key, term_help[i].key2); else fprintf(stderr, "[%c]", term_help[i].key); fprintf(stderr, "\t%s\n", term_help[i].desc); } fprintf(stderr, "\nAlso, the number row (starting at 1, ending at 0) gives you jump points into the current track at 10%% intervals.\n"); fprintf(stderr, "\n"); } break; case MPG123_FRAME_INDEX_KEY: case MPG123_VARIOUS_INFO_KEY: if(param.verbose) fprintf(stderr, "\n"); switch(val) /* because of tolower() ... */ { case MPG123_FRAME_INDEX_KEY: print_index(fr); { long accurate; if(mpg123_getstate(fr, MPG123_ACCURATE, &accurate, NULL) == MPG123_OK) fprintf(stderr, "Accurate position: %s\n", (accurate == 0 ? "no" : "yes")); else error1("Unable to get state: %s", mpg123_strerror(fr)); } break; case MPG123_VARIOUS_INFO_KEY: { const char* curdec = mpg123_current_decoder(fr); if(curdec == NULL) fprintf(stderr, "Cannot get decoder info!\n"); else fprintf(stderr, "Active decoder: %s\n", curdec); } } break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { off_t len; int num; num = val == '0' ? 10 : val - '0'; --num; /* from 0 to 9 */ /* Do not swith to seekmode() here, as we are jumping once to a specific position. Dropping buffer contents is enough and there is no race filling the buffer or waiting for more incremental seek orders. */ len = mpg123_length(fr); out123_pause(ao); out123_drop(ao); if(len > 0) mpg123_seek(fr, (off_t)( (num/10.)*len ), SEEK_SET); } break; case MPG123_BOOKMARK_KEY: continue_msg("BOOKMARK"); break; default: ; } }