type
stringclasses 5
values | content
stringlengths 9
163k
|
|---|---|
defines
|
#define mach_vm_allocate vm_allocate
|
defines
|
#define mach_vm_deallocate vm_deallocate
|
defines
|
#define mach_vm_write vm_write
|
defines
|
#define mach_vm_remap vm_remap
|
defines
|
#define mach_vm_protect vm_protect
|
defines
|
#define NSLookupSymbolInImage(...) ((void)0)
|
defines
|
#define NSAddressOfSymbol(...) ((void)0)
|
defines
|
#define RDErrorLog(format, ...) fprintf(stderr, "%s:%d:\n\terror: "format"\n", \
|
defines
|
#define LC_SEGMENT_ARCH_INDEPENDENT LC_SEGMENT_64
|
defines
|
#define LC_SEGMENT_ARCH_INDEPENDENT LC_SEGMENT
|
includes
|
#include <errno.h>
|
includes
|
#include <stdio.h>
|
includes
|
#include <stdlib.h>
|
includes
|
#include <stdbool.h>
|
includes
|
#include <string.h>
|
includes
|
#include <math.h>
|
includes
|
#include <teatime.h>
|
defines
|
#define TEATIME_BREAKONERROR(FN,RC) if ((RC = teatime_check_gl_errors(__LINE__, #FN )) < 0) break
|
defines
|
#define TEATIME_BREAKONERROR_FB(FN,RC) if ((RC = teatime_check_gl_fb_errors(__LINE__, #FN )) < 0) break
|
defines
|
#define TEA_ENCRYPT_SOURCE \
|
defines
|
#define TEA_DECRYPT_SOURCE \
|
functions
|
void teatime_cleanup(teatime_t *obj)
{
if (obj) {
teatime_delete_program(obj);
teatime_delete_textures(obj);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
glDeleteFramebuffersEXT(1, &(obj->ofb));
glFlush();
free(obj);
obj = NULL;
}
|
functions
|
int teatime_set_viewport(teatime_t *obj, uint32_t ilen)
{
uint32_t texsz = (uint32_t)((long)(sqrt(ilen / 4.0)));
if (obj && texsz > 0 && texsz < (GLuint)obj->maxtexsz) {
/* viewport mapping 1:1 pixel = texel = data mapping */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, texsz, 0.0, texsz);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glViewport(0, 0, texsz, texsz);
obj->tex_size = texsz;
fprintf(stderr, "Texture size: %u x %u\n", texsz, texsz);
return 0;
}
|
functions
|
else if (obj) {
fprintf(stderr, "Max. texture size is %d. Calculated: %u from input length: %u\n",
obj->maxtexsz, texsz, ilen);
}
|
functions
|
int teatime_create_textures(teatime_t *obj, const uint32_t *input, uint32_t ilen)
{
if (obj && input && ilen > 0) {
int rc = 0;
do {
uint32_t texsz = (uint32_t)((long)(sqrt(ilen / 4.0)));
if (texsz != obj->tex_size) {
fprintf(stderr, "Viewport texture size(%u) != Input texture size (%u)\n",
obj->tex_size, texsz);
rc = -EINVAL;
break;
}
|
functions
|
int teatime_read_textures(teatime_t *obj, uint32_t *output, uint32_t olen)
{
if (obj && output && olen > 0 && obj->otexid > 0) {
int rc = 0;
do {
uint32_t texsz = (uint32_t)((long)(sqrt(olen / 4.0)));
if (texsz != obj->tex_size) {
fprintf(stderr, "Viewport texture size(%u) != Input texture size (%u)\n",
obj->tex_size, texsz);
rc = -EINVAL;
break;
}
|
functions
|
int teatime_create_program(teatime_t *obj, const char *source)
{
if (obj && source) {
int rc = 0;
do {
obj->program = glCreateProgram();
TEATIME_BREAKONERROR(glCreateProgram, rc);
obj->shader = glCreateShader(GL_FRAGMENT_SHADER_ARB);
TEATIME_BREAKONERROR(glCreateShader, rc);
glShaderSource(obj->shader, 1, &source, NULL);
TEATIME_BREAKONERROR(glShaderSource, rc);
glCompileShader(obj->shader);
rc = teatime_check_shader_errors(obj->shader);
if (rc < 0) break;
TEATIME_BREAKONERROR(glCompileShader, rc);
glAttachShader(obj->program, obj->shader);
TEATIME_BREAKONERROR(glAttachShader, rc);
glLinkProgram(obj->program);
rc = teatime_check_program_errors(obj->program);
if (rc < 0) break;
TEATIME_BREAKONERROR(glLinkProgram, rc);
obj->locn_input = glGetUniformLocation(obj->program, "idata");
TEATIME_BREAKONERROR(glGetUniformLocation, rc);
obj->locn_output = glGetUniformLocation(obj->program, "odata");
TEATIME_BREAKONERROR(glGetUniformLocation, rc);
obj->locn_key = glGetUniformLocation(obj->program, "ikey");
TEATIME_BREAKONERROR(glGetUniformLocation, rc);
obj->locn_rounds = glGetUniformLocation(obj->program, "rounds");
TEATIME_BREAKONERROR(glGetUniformLocation, rc);
rc = 0;
}
|
functions
|
int teatime_run_program(teatime_t *obj, const uint32_t ikey[4], uint32_t rounds)
{
if (obj && obj->program > 0) {
int rc = 0;
do {
glUseProgram(obj->program);
TEATIME_BREAKONERROR(glUseProgram, rc);
glActiveTexture(GL_TEXTURE0);
TEATIME_BREAKONERROR(glActiveTexture, rc);
glBindTexture(GL_TEXTURE_2D, obj->itexid);
TEATIME_BREAKONERROR(glBindTexture, rc);
glUniform1i(obj->locn_input, 0);
TEATIME_BREAKONERROR(glUniform1i, rc);
glActiveTexture(GL_TEXTURE1);
TEATIME_BREAKONERROR(glActiveTexture, rc);
glBindTexture(GL_TEXTURE_2D, obj->otexid);
TEATIME_BREAKONERROR(glBindTexture, rc);
glUniform1i(obj->locn_output, 1);
TEATIME_BREAKONERROR(glUniform1i, rc);
glUniform4uiv(obj->locn_key, 1, ikey);
TEATIME_BREAKONERROR(glUniform1uiv, rc);
glUniform1ui(obj->locn_rounds, rounds);
TEATIME_BREAKONERROR(glUniform1ui, rc);
glFinish();
glPolygonMode(GL_FRONT, GL_FILL);
/* render */
glBegin(GL_QUADS);
glTexCoord2i(0, 0);
glVertex2i(0, 0);
//glTexCoord2i(obj->tex_size, 0);
glTexCoord2i(1, 0);
glVertex2i(obj->tex_size, 0);
//glTexCoord2i(obj->tex_size, obj->tex_size);
glTexCoord2i(1, 1);
glVertex2i(obj->tex_size, obj->tex_size);
glTexCoord2i(0, 1);
//glTexCoord2i(0, obj->tex_size);
glVertex2i(0, obj->tex_size);
glEnd();
glFinish();
TEATIME_BREAKONERROR_FB(Rendering, rc);
TEATIME_BREAKONERROR(Rendering, rc);
rc = 0;
}
|
functions
|
void teatime_delete_textures(teatime_t *obj)
{
if (obj) {
if (obj->itexid != 0) {
glDeleteTextures(1, &(obj->itexid));
obj->itexid = 0;
}
|
functions
|
void teatime_delete_program(teatime_t *obj)
{
if (obj) {
if (obj->shader > 0 && obj->program > 0) {
glDetachShader(obj->program, obj->shader);
}
|
functions
|
void teatime_print_version(FILE *fp)
{
const GLubyte *version = NULL;
version = glGetString(GL_VERSION);
fprintf(fp, "GL Version: %s\n", (const char *)version);
version = glGetString(GL_SHADING_LANGUAGE_VERSION);
fprintf(fp, "GLSL Version: %s\n", (const char *)version);
version = glGetString(GL_VENDOR);
fprintf(fp, "GL Vendor: %s\n", (const char *)version);
}
|
functions
|
int teatime_check_gl_version(uint32_t *major, uint32_t *minor)
{
const GLubyte *version = NULL;
version = glGetString(GL_VERSION);
if (version) {
uint32_t ver[2] = { 0, 0 }
|
functions
|
int teatime_check_gl_errors(int line, const char *fn_name)
{
GLenum err = glGetError();
if (err != GL_NO_ERROR) {
const GLubyte *estr = gluErrorString(err);
fprintf(stderr, "%s(): GL Error(%d) on line %d: %s\n", fn_name,
err, line, (const char *)estr);
return -1;
}
|
functions
|
int teatime_check_gl_fb_errors(int line, const char *fn_name)
{
GLenum st = (GLenum)glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
switch (st) {
case GL_FRAMEBUFFER_COMPLETE_EXT:
return 0;
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
fprintf(stderr, "%s(): GL FB error on line %d: incomplete attachment\n", fn_name, line);
break;
case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
fprintf(stderr, "%s(): GL FB error on line %d: unsupported\n", fn_name, line);
break;
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
fprintf(stderr, "%s(): GL FB error on line %d: incomplete missing attachment\n", fn_name, line);
break;
case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
fprintf(stderr, "%s(): GL FB error on line %d: incomplete dimensions\n", fn_name, line);
break;
case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
fprintf(stderr, "%s(): GL FB error on line %d: incomplete formats\n", fn_name, line);
break;
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
fprintf(stderr, "%s(): GL FB error on line %d: incomplete draw buffer\n", fn_name, line);
break;
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
fprintf(stderr, "%s(): GL FB error on line %d: incomplete read buffer\n", fn_name, line);
break;
default:
fprintf(stderr, "%s(): GL FB error on line %d: Unknown. Error Value: %d\n", fn_name, line, st);
break;
}
|
functions
|
int teatime_check_program_errors(GLuint program)
{
GLint ilen = 0;
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &ilen);
if (ilen > 1) {
GLsizei wb = 0;
GLchar *buf = calloc(ilen, sizeof(GLchar));
if (!buf) {
fprintf(stderr, "Out of memory allocating %d bytes\n", ilen);
return -ENOMEM;
}
|
functions
|
int teatime_check_shader_errors(GLuint shader)
{
GLint ilen = 0;
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &ilen);
if (ilen > 1) {
GLsizei wb = 0;
GLchar *buf = calloc(ilen, sizeof(GLchar));
if (!buf) {
fprintf(stderr, "Out of memory allocating %d bytes\n", ilen);
return -ENOMEM;
}
|
functions
|
void main(void) {\n" \
" uvec4 x = texture(idata, gl_TexCoord[0].st);\n" \
" uint delta = uint(0x9e3779b9); \n" \
" uint sum = uint(0); \n" \
" for (uint i = uint(0); i < rounds; ++i) {\n" \
" sum += delta; \n" \
" x[0] += (((x[1] << 4) + ikey[0]) ^ (x[1] + sum)) ^ ((x[1] >> 5) + ikey[1]);\n" \
" x[1] += (((x[0] << 4) + ikey[2]) ^ (x[0] + sum)) ^ ((x[0] >> 5) + ikey[3]);\n" \
" x[2] += (((x[3] << 4) + ikey[0]) ^ (x[3] + sum)) ^ ((x[3] >> 5) + ikey[1]);\n" \
" x[3] += (((x[2] << 4) + ikey[2]) ^ (x[2] + sum)) ^ ((x[2] >> 5) + ikey[3]);\n" \
" }
|
functions
|
void main(void) {\n" \
" uvec4 x = texture(idata, gl_TexCoord[0].st);\n" \
" uint delta = uint(0x9e3779b9); \n" \
" uint sum = delta * rounds; \n" \
" for (uint i = uint(0); i < rounds; ++i) {\n" \
" x[1] -= (((x[0] << 4) + ikey[2]) ^ (x[0] + sum)) ^ ((x[0] >> 5) + ikey[3]);\n" \
" x[0] -= (((x[1] << 4) + ikey[0]) ^ (x[1] + sum)) ^ ((x[1] >> 5) + ikey[1]);\n" \
" x[3] -= (((x[2] << 4) + ikey[2]) ^ (x[2] + sum)) ^ ((x[2] >> 5) + ikey[3]);\n" \
" x[2] -= (((x[3] << 4) + ikey[0]) ^ (x[3] + sum)) ^ ((x[3] >> 5) + ikey[1]);\n" \
" sum -= delta; \n" \
" }
|
functions
|
task main()
{ //Program begins, insert code within curly braces
while (true)
{
//Input Conveior Belt
startMotor(InputBeltMotor, 127);
wait(2.5);
stopMotor(InputBeltMotor);
//Elevator
startMotor(ElevatorMotor, 127);
wait(1.5);
stopMotor(ElevatorMotor);
//Move Cookie To line follower
do
{
startMotor(OutputBeltMotor, -127);
}
|
includes
|
#include <math.h>
|
includes
|
#include <stdlib.h>
|
functions
|
ALuint NextPowerOf2(ALuint value)
{
ALuint powerOf2 = 1;
if(value)
{
value--;
while(value)
{
value >>= 1;
powerOf2 <<= 1;
}
|
functions
|
ALfloat DelayLineOut(DelayLine *Delay, ALuint offset)
{
return Delay->Line[offset&Delay->Mask];
}
|
functions
|
ALvoid DelayLineIn(DelayLine *Delay, ALuint offset, ALfloat in)
{
Delay->Line[offset&Delay->Mask] = in;
}
|
functions
|
ALfloat EarlyDelayLineOut(ALverbState *State, ALuint index)
{
return State->Early.Coeff[index] *
DelayLineOut(&State->Early.Delay[index],
State->Offset - State->Early.Offset[index]);
}
|
functions
|
ALvoid EarlyReflection(ALverbState *State, ALfloat in, ALfloat *out)
{
ALfloat d[4], v, f[4];
// Obtain the decayed results of each early delay line.
d[0] = EarlyDelayLineOut(State, 0);
d[1] = EarlyDelayLineOut(State, 1);
d[2] = EarlyDelayLineOut(State, 2);
d[3] = EarlyDelayLineOut(State, 3);
/* The following uses a lossless scattering junction from waveguide
* theory. It actually amounts to a householder mixing matrix, which
* will produce a maximally diffuse response, and means this can probably
* be considered a simple feedback delay network (FDN).
* N
* ---
* \
* v = 2/N / d_i
* ---
* i=1
*/
v = (d[0] + d[1] + d[2] + d[3]) * 0.5f;
// The junction is loaded with the input here.
v += in;
// Calculate the feed values for the delay lines.
f[0] = v - d[0];
f[1] = v - d[1];
f[2] = v - d[2];
f[3] = v - d[3];
// Refeed the delay lines.
DelayLineIn(&State->Early.Delay[0], State->Offset, f[0]);
DelayLineIn(&State->Early.Delay[1], State->Offset, f[1]);
DelayLineIn(&State->Early.Delay[2], State->Offset, f[2]);
DelayLineIn(&State->Early.Delay[3], State->Offset, f[3]);
// Output the results of the junction for all four lines.
out[0] = State->Early.Gain * f[0];
out[1] = State->Early.Gain * f[1];
out[2] = State->Early.Gain * f[2];
out[3] = State->Early.Gain * f[3];
}
|
functions
|
ALfloat LateAllPassInOut(ALverbState *State, ALuint index, ALfloat in)
{
ALfloat out;
out = State->Late.ApCoeff[index] *
DelayLineOut(&State->Late.ApDelay[index],
State->Offset - State->Late.ApOffset[index]);
out -= (State->Late.ApFeedCoeff * in);
DelayLineIn(&State->Late.ApDelay[index], State->Offset,
(State->Late.ApFeedCoeff * out) + in);
return out;
}
|
functions
|
ALfloat LateDelayLineOut(ALverbState *State, ALuint index)
{
return State->Late.Coeff[index] *
DelayLineOut(&State->Late.Delay[index],
State->Offset - State->Late.Offset[index]);
}
|
functions
|
ALfloat LateLowPassInOut(ALverbState *State, ALuint index, ALfloat in)
{
State->Late.LpSample[index] = in +
((State->Late.LpSample[index] - in) * State->Late.LpCoeff[index]);
return State->Late.LpSample[index];
}
|
functions
|
ALvoid LateReverb(ALverbState *State, ALfloat *in, ALfloat *out)
{
ALfloat d[4], f[4];
// Obtain the decayed results of the cyclical delay lines, and add the
// corresponding input channels attenuated by density. Then pass the
// results through the low-pass filters.
d[0] = LateLowPassInOut(State, 0, (State->Late.DensityGain * in[0]) +
LateDelayLineOut(State, 0));
d[1] = LateLowPassInOut(State, 1, (State->Late.DensityGain * in[1]) +
LateDelayLineOut(State, 1));
d[2] = LateLowPassInOut(State, 2, (State->Late.DensityGain * in[2]) +
LateDelayLineOut(State, 2));
d[3] = LateLowPassInOut(State, 3, (State->Late.DensityGain * in[3]) +
LateDelayLineOut(State, 3));
// To help increase diffusion, run each line through an all-pass filter.
// The order of the all-pass filters is selected so that the shortest
// all-pass filter will feed the shortest delay line.
d[0] = LateAllPassInOut(State, 1, d[0]);
d[1] = LateAllPassInOut(State, 3, d[1]);
d[2] = LateAllPassInOut(State, 0, d[2]);
d[3] = LateAllPassInOut(State, 2, d[3]);
/* Late reverb is done with a modified feedback delay network (FDN)
* topology. Four input lines are each fed through their own all-pass
* filter and then into the mixing matrix. The four outputs of the
* mixing matrix are then cycled back to the inputs. Each output feeds
* a different input to form a circlular feed cycle.
*
* The mixing matrix used is a 4D skew-symmetric rotation matrix derived
* using a single unitary rotational parameter:
*
* [ d, a, b, c ] 1 = a^2 + b^2 + c^2 + d^2
* [ -a, d, c, -b ]
* [ -b, -c, d, a ]
* [ -c, b, -a, d ]
*
* The rotation is constructed from the effect's diffusion parameter,
* yielding: 1 = x^2 + 3 y^2; where a, b, and c are the coefficient y
* with differing signs, and d is the coefficient x. The matrix is thus:
*
* [ x, y, -y, y ] x = 1 - (0.5 diffusion^3)
* [ -y, x, y, y ] y = sqrt((1 - x^2) / 3)
* [ y, -y, x, y ]
* [ -y, -y, -y, x ]
*
* To reduce the number of multiplies, the x coefficient is applied with
* the cyclical delay line coefficients. Thus only the y coefficient is
* applied when mixing, and is modified to be: y / x.
*/
f[0] = d[0] + (State->Late.MixCoeff * ( d[1] - d[2] + d[3]));
f[1] = d[1] + (State->Late.MixCoeff * (-d[0] + d[2] + d[3]));
f[2] = d[2] + (State->Late.MixCoeff * ( d[0] - d[1] + d[3]));
f[3] = d[3] + (State->Late.MixCoeff * (-d[0] - d[1] - d[2]));
// Output the results of the matrix for all four cyclical delay lines,
// attenuated by the late reverb gain (which is attenuated by the 'x'
// mix coefficient).
out[0] = State->Late.Gain * f[0];
out[1] = State->Late.Gain * f[1];
out[2] = State->Late.Gain * f[2];
out[3] = State->Late.Gain * f[3];
// The delay lines are fed circularly in the order:
// 0 -> 1 -> 3 -> 2 -> 0 ...
DelayLineIn(&State->Late.Delay[0], State->Offset, f[2]);
DelayLineIn(&State->Late.Delay[1], State->Offset, f[0]);
DelayLineIn(&State->Late.Delay[2], State->Offset, f[3]);
DelayLineIn(&State->Late.Delay[3], State->Offset, f[1]);
}
|
functions
|
ALvoid ReverbInOut(ALverbState *State, ALfloat in, ALfloat *early, ALfloat *late)
{
ALfloat taps[4];
// Low-pass filter the incoming sample.
in = lpFilter2P(&State->LpFilter, 0, in);
// Feed the initial delay line.
DelayLineIn(&State->Delay, State->Offset, in);
// Calculate the early reflection from the first delay tap.
in = DelayLineOut(&State->Delay, State->Offset - State->Tap[0]);
EarlyReflection(State, in, early);
// Calculate the late reverb from the last four delay taps.
taps[0] = DelayLineOut(&State->Delay, State->Offset - State->Tap[1]);
taps[1] = DelayLineOut(&State->Delay, State->Offset - State->Tap[2]);
taps[2] = DelayLineOut(&State->Delay, State->Offset - State->Tap[3]);
taps[3] = DelayLineOut(&State->Delay, State->Offset - State->Tap[4]);
LateReverb(State, taps, late);
// Step all delays forward one sample.
State->Offset++;
}
|
functions
|
ALvoid VerbDestroy(ALeffectState *effect)
{
ALverbState *State = (ALverbState*)effect;
if(State)
{
free(State->SampleBuffer);
State->SampleBuffer = NULL;
free(State);
}
|
functions
|
ALint aluCart2LUTpos(ALfloat re, ALfloat im)
{
ALint pos = 0;
ALfloat denom = aluFabs(re) + aluFabs(im);
if(denom > 0.0f)
pos = (ALint)(QUADRANT_NUM*aluFabs(im) / denom + 0.5);
if(re < 0.0)
pos = 2 * QUADRANT_NUM - pos;
if(im < 0.0)
pos = LUT_NUM - pos;
return pos%LUT_NUM;
}
|
functions
|
ALvoid VerbUpdate(ALeffectState *effect, ALCcontext *Context, ALeffect *Effect)
{
ALverbState *State = (ALverbState*)effect;
ALuint index;
ALfloat length, mixCoeff, cw, g, coeff;
ALfloat hfRatio = Effect->Reverb.DecayHFRatio;
// Calculate the master low-pass filter (from the master effect HF gain).
cw = cos(2.0 * M_PI * Effect->Reverb.HFReference / Context->Frequency);
g = __max(Effect->Reverb.GainHF, 0.0001f);
State->LpFilter.coeff = 0.0f;
if(g < 0.9999f) // 1-epsilon
State->LpFilter.coeff = (1 - g*cw - aluSqrt(2*g*(1-cw) - g*g*(1 - cw*cw))) / (1 - g);
// Calculate the initial delay taps.
length = Effect->Reverb.ReflectionsDelay;
State->Tap[0] = (ALuint)(length * Context->Frequency);
length += Effect->Reverb.LateReverbDelay;
/* The four inputs to the late reverb are decorrelated to smooth the
* initial reverb and reduce harsh echos. The timings are calculated as
* multiples of a fraction of the smallest cyclical delay time. This
* result is then adjusted so that the first tap occurs immediately (all
* taps are reduced by the shortest fraction).
*
* offset[index] = ((FRACTION MULTIPLIER^index) - 1) delay
*/
for(index = 0;index < 4;index++)
{
length += LATE_LINE_LENGTH[0] *
(1.0f + (Effect->Reverb.Density * LATE_LINE_MULTIPLIER)) *
(DECO_FRACTION * (pow(DECO_MULTIPLIER, (ALfloat)index) - 1.0f));
State->Tap[1 + index] = (ALuint)(length * Context->Frequency);
}
|
includes
|
#include <stdio.h>
|
includes
|
#include <unistd.h>
|
includes
|
#include <fcntl.h>
|
includes
|
#include <errno.h>
|
includes
|
#include <assert.h>
|
includes
|
#include <sys/epoll.h>
|
structs
|
struct state
{
reactor_handler input;
reactor_handler output;
char buffer[4096];
data remaining;
};
|
functions
|
int fill(struct state *state)
{
ssize_t n;
n = read(0, state->buffer, sizeof state->buffer);
if (n == 0)
{
reactor_delete(&state->input, 0);
reactor_delete(&state->output, 1);
return -1;
}
|
functions
|
int flush(struct state *state)
{
ssize_t n;
n = write(1, data_base(state->remaining), data_size(state->remaining));
if (n == -1 && errno == EAGAIN)
return -1;
assert(n > 0);
state->remaining = data_select(state->remaining, n, data_size(state->remaining) - n);
if (!data_size(state->remaining))
{
reactor_modify(&state->input, 0, EPOLLIN | EPOLLET);
reactor_modify(&state->output, 1, 0);
}
|
functions
|
void input(reactor_event *event)
{
struct state *state = event->state;
int e;
while (!data_size(state->remaining))
{
e = fill(state);
if (e == -1)
break;
e = flush(state);
if (e == -1)
break;
}
|
functions
|
void output(reactor_event *event)
{
struct state *state = event->state;
int e;
while (data_size(state->remaining))
{
e = flush(state);
if (e == -1)
break;
}
|
main
|
int main()
{
struct state state = {0}
|
functions
|
int NextState(int m, char* pattern, int state, int symbol) {
if (state < m && pattern[state] == symbol) {
return state + 1;
}
|
functions
|
void GenerateTable(int m, char* pattern, int Table[m][CHAR_MAX]) {
for (int state = 0, symbol = 0; symbol < CHAR_MAX || (symbol = 0, ++state) < m; symbol++) {
Table[state][symbol] = NextState(m, pattern, state, symbol);
}
|
functions
|
int Search(int n, char* haystack, int m, char* needle) {
int Table[m + 1][CHAR_MAX], state = 0;
GenerateTable(m + 1, needle, Table);
for (int i = 0; i < n; i++) {
state = Table[state][haystack[i]];
if (state == m) {
return (i - m + 1);
}
|
includes
|
#include <stdio.h>
|
includes
|
#include <sys/socket.h>
|
includes
|
#include <sys/wait.h>
|
includes
|
#include <stdlib.h>
|
includes
|
#include <string.h>
|
includes
|
#include <netinet/in.h>
|
includes
|
#include <time.h>
|
includes
|
#include <arpa/inet.h>
|
includes
|
#include <unistd.h>
|
includes
|
#include <errno.h>
|
includes
|
#include <signal.h>
|
defines
|
#define MAXLINE 4096 /* max text line length */
|
defines
|
#define LISTENQ 1024 /* 2nd argument to listen() , 排队的最大连接数*/
|
defines
|
#define LISTEN_PORT 9669 //服务器监听端口
|
structs
|
struct sockaddr
{
unsigned short int sa_family;
char sa_data[14];
};
|
structs
|
struct socketaddr_in
{
unsigned short int sin_family;
uint16_t sin_port;
struct in_addr sin_addr;
unsigned char sin_zero[8];
};
|
structs
|
struct in_addr
{
uint32_t s_addr;
};
|
includes
|
#include <compiler.h>
|
includes
|
#include <common/strres.h>
|
includes
|
#include <cpucore.h>
|
includes
|
#include <pccore.h>
|
includes
|
#include <io/iocore.h>
|
includes
|
#include <generic/memdbg32.h>
|
defines
|
#define MEMDBG32_MAXMEM 16
|
defines
|
#define MEMDBG32_DATAPERLINE 128
|
defines
|
#define MEMDBG32_LEFTMARGIN 8
|
functions
|
void memdbg32_initialize(void) {
ZeroMemory(&memdbg32, sizeof(memdbg32));
memdbg32.width = (MEMDBG32_BLOCKW * MEMDBG32_DATAPERLINE) + MEMDBG32_LEFTMARGIN;
memdbg32.height = (MEMDBG32_BLOCKH * 2 * MEMDBG32_MAXMEM) + 8;
}
|
functions
|
void memdbg32_getsize(int *width, int *height) {
if (width) {
*width = memdbg32.width;
}
|
functions
|
REG8 memdbg32_process(void) {
return(MEMDBG32_FLAGDRAW);
}
|
functions
|
BOOL memdbg32_paint(CMNVRAM *vram, CMNPALCNV cnv, BOOL redraw) {
UINT mode;
UINT8 use[MEMDBG32_MAXMEM*MEMDBG32_DATAPERLINE*2 + 256];
UINT32 pd[1024];
UINT pdmax;
UINT i, j;
UINT32 pde;
UINT32 pdea;
UINT32 pte;
char str[4];
mode = 0;
if (CPU_STAT_PM) {
mode = 1;
}
|
functions
|
else if (!use[pte >> 12]) {
use[pte >> 12] = MEMDBG32_PALPAGE0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.