void draw_solid_rectangle(Graphic *graphic, int x1, int y1, int x2, int y2, unsigned color) { int x, y; int tmp; assert(color <= MAX_COLOR_REGISTERS); if (x1 > x2) { EXCHANGE(x1, x2, tmp); } if (y1 > y2) { EXCHANGE(y1, y2, tmp); } if (x2 < 0 || x1 >= graphic->actual_width || y2 < 0 || y1 >= graphic->actual_height) return; if (x1 < 0) x1 = 0; if (x2 >= graphic->actual_width) x2 = graphic->actual_width - 1; if (y1 < 0) y1 = 0; if (y2 >= graphic->actual_height) y2 = graphic->actual_height - 1; if (color < MAX_COLOR_REGISTERS) graphic->color_registers_used[color] = 1; for (y = y1; y <= y2; y++) for (x = x1; x <= x2; x++) _draw_pixel(graphic, x, y, color); }
void draw_solid_line(Graphic *graphic, int x1, int y1, int x2, int y2, unsigned color) { int x, y; int dx, dy; int dir, diff; assert(color <= MAX_COLOR_REGISTERS); dx = abs(x1 - x2); dy = abs(y1 - y2); if (dx > dy) { if (x1 > x2) { int tmp; EXCHANGE(x1, x2, tmp); EXCHANGE(y1, y2, tmp); } if (y1 < y2) dir = 1; else if (y1 > y2) dir = -1; else dir = 0; diff = 0; y = y1; for (x = x1; x <= x2; x++) { if (diff >= dx) { diff -= dx; y += dir; } diff += dy; draw_solid_pixel(graphic, x, y, color); } } else { if (y1 > y2) { int tmp; EXCHANGE(x1, x2, tmp); EXCHANGE(y1, y2, tmp); } if (x1 < x2) dir = 1; else if (x1 > x2) dir = -1; else dir = 0; diff = 0; x = x1; for (y = y1; y <= y2; y++) { if (diff >= dy) { diff -= dy; x += dir; } diff += dx; draw_solid_pixel(graphic, x, y, color); } } }
static SplitSize uPartnStabRefine( const RefinementParm familyParm[], const RefinementParm refnParm[], PartitionStack *const UpsilonStack) /* The partition stack to refine. */ { #ifdef xxxx CellPartitionStack *xUpsilonStack = familyParm[0].ptrParm; Partition *Lambda = xUpsilonStack->basePartn; Unsigned i = refnParm[0].intParm, j = refnParm[1].intParm; Unsigned m, k, r, last, left, right, temp, startNewCell, pt, t; UnsignedS *const pointList = UpsilonStack->pointList, *const invPointList = UpsilonStack->invPointList, *const parent = UpsilonStack->parent, *const startCell = UpsilonStack->startCell, *const cellNumber = UpsilonStack->cellNumber, *const cellSize = UpsilonStack->cellSize, *const xCellList = xUpsilonStack->cellList, *const xCellGroupNumber = xUpsilonStack->cellGroupNumber, *const xStartCellGroup = xUpsilonStack->startCellGroup, *const xCellGroupSize = xUpsilonStack->cellGroupSize, *const LambdaCellNumber = Lambda->cellNumber; SplitSize split; BOOLEAN cellSplits; /* First check if the refinement acts nontrivially on UpsilonTop. If not return immediately. */ cellSplits = FALSE; for ( m = startCell[cellToSplit]+1 , last = m -1 + cellSize[cellToSplit] ; m < last ; ++m ) if ( (xCellGroupNumber[LambdaCellNumber[pointList[m]]] == j) != (xCellGroupNumber[LambdaCelllNumber[pointList[m-1]]] == j) ) { cellSplits = TRUE; break; } if ( !cellSplits ) { split.oldCellSize = cellSize[cellToSplit]; split.newCellSize = 0; return split; } /* Now split cell cellToSplit of UpsilonTop. A variation of the splitting algorithm used in quicksort is applied. */ if ( cellSize[i] <= xUpsilonStack->totalGroupSize[j] ) { left = startCell[i] - 1; right = startCell[i] + cellSize[i]; while ( left < right ) { while ( xCellGroupNumber[LambdaCellNumber[pointList[++left]]] != j ) ; while ( xCellGroupNumber[LambdaCellNumber[pointList[--right]]] == j ) ; if ( left < right ) { EXCHANGE( pointList[left], pointList[right], temp) EXCHANGE( invPointList[pointList[left]], invPointList[pointList[right]], temp) } } startNewCell = left; }
static SplitSize setStabRefine( const RefinementParm familyParm[], /* Family parm: Lambda. */ const RefinementParm refnParm[], /* Refinement parm: i. */ PartitionStack *const UpsilonStack) /* The partition stack to refine. */ { PointSet *Lambda = familyParm[0].ptrParm; Unsigned cellToSplit = refnParm[0].intParm; Unsigned m, last, i, j, temp, inLambdaCount = 0, outLambdaCount = 0; UnsignedS *const pointList = UpsilonStack->pointList, *const invPointList = UpsilonStack->invPointList, *const cellNumber = UpsilonStack->cellNumber, *const parent = UpsilonStack->parent, *const startCell = UpsilonStack->startCell, *const cellSize = UpsilonStack->cellSize; char *inSet = Lambda->inSet; SplitSize split; /* First check if the refinement acts nontrivially on UpsilonTop. If not return immediately. */ for ( m = startCell[cellToSplit] , last = m + cellSize[cellToSplit] ; m < last && (inLambdaCount == 0 || outLambdaCount == 0) ; ++m ) if ( inSet[pointList[m]] ) ++inLambdaCount; else ++outLambdaCount; if ( inLambdaCount == 0 || outLambdaCount == 0 ) { split.oldCellSize = cellSize[cellToSplit]; split.newCellSize = 0; return split; } /* Now split cell cellToSplit of UpsilonTop. A variation of the splitting algorithm used in quicksort is applied. */ i = startCell[cellToSplit]-1; j = last; while ( i < j ) { while ( !inSet[pointList[++i]] ); while ( inSet[pointList[--j]] ); if ( i < j ) { EXCHANGE( pointList[i], pointList[j], temp) EXCHANGE( invPointList[pointList[i]], invPointList[pointList[j]], temp) } } ++UpsilonStack->height; for ( m = i ; m < last ; ++m ) cellNumber[pointList[m]] = UpsilonStack->height; startCell[UpsilonStack->height] = i; parent[UpsilonStack->height] = cellToSplit; cellSize[UpsilonStack->height] = last - i; cellSize[cellToSplit] -= (last - i); split.oldCellSize = cellSize[cellToSplit]; split.newCellSize = cellSize[UpsilonStack->height]; return split; }
SplitSize partnStabRefine( const RefinementParm familyParm[], /* Family parm: Lambda. */ const RefinementParm refnParm[], /* Refinement parm: i. */ PartitionStack *const UpsilonStack) /* The partition stack to refine. */ { Partition *Lambda = familyParm[0].ptrParm; Unsigned cellToSplit = refnParm[0].intParm, LambdaCellToUse = refnParm[1].intParm; Unsigned m, last, i, j, temp; UnsignedS *const pointList = UpsilonStack->pointList, *const invPointList = UpsilonStack->invPointList, *const parent = UpsilonStack->parent, *const startCell = UpsilonStack->startCell, *const cellSize = UpsilonStack->cellSize; SplitSize split; BOOLEAN cellSplits; /* First check if the refinement acts nontrivially on UpsilonTop. If not return immediately. */ cellSplits = FALSE; for ( m = startCell[cellToSplit]+1 , last = m -1 + cellSize[cellToSplit] ; m < last ; ++m ) if ( (Lambda->cellNumber[pointList[m]] == LambdaCellToUse) != (Lambda->cellNumber[pointList[m-1]] == LambdaCellToUse) ) { cellSplits = TRUE; break; } if ( !cellSplits ) { split.oldCellSize = cellSize[cellToSplit]; split.newCellSize = 0; return split; } /* Now split cell cellToSplit of UpsilonTop. A variation of the splitting algorithm used in quicksort is applied. */ i = startCell[cellToSplit]-1; j = last; while ( i < j ) { while ( Lambda->cellNumber[pointList[++i]] != LambdaCellToUse ) ; while ( Lambda->cellNumber[pointList[--j]] == LambdaCellToUse ) ; if ( i < j ) { EXCHANGE( pointList[i], pointList[j], temp) EXCHANGE( invPointList[pointList[i]], invPointList[pointList[j]], temp) } } ++UpsilonStack->height; for ( m = i ; m < last ; ++m ) UpsilonStack->cellNumber[pointList[m]] = UpsilonStack->height; startCell[UpsilonStack->height] = i; parent[UpsilonStack->height] = cellToSplit; cellSize[UpsilonStack->height] = last - i; cellSize[cellToSplit] -= (last - i); split.oldCellSize = cellSize[cellToSplit]; split.newCellSize = cellSize[UpsilonStack->height]; return split; }
SplitSize pointStabRefine( const RefinementParm familyParm[], /* No family parms. */ const RefinementParm refnParm[], /* parm[0] = alpha, parm[1] = i. */ PartitionStack *const UpsilonStack) /* The partition stack, as above. */ { const Unsigned alpha = refnParm[0].intParm, cellToSplit = refnParm[1].intParm; Unsigned oldAlphaPosition, newAlphaPosition, temp; Unsigned height = UpsilonStack->height; UnsignedS *const pointList = UpsilonStack->pointList, *const invPointList = UpsilonStack->invPointList, *const cellNumber = UpsilonStack->cellNumber, *const parent = UpsilonStack->parent, *const startCell = UpsilonStack->startCell, *const cellSize = UpsilonStack->cellSize; SplitSize split; /* First check if the refinement acts nontrivially on UpsilonTop. If not return immediately. */ if ( cellNumber[alpha] != cellToSplit || cellSize[cellToSplit] == 1 ) { split.oldCellSize = cellSize[cellToSplit]; split.newCellSize = 0; return split; } /* Now split cell cellToSplit of UpsilonTop. */ oldAlphaPosition = invPointList[alpha]; newAlphaPosition = startCell[cellToSplit] + cellSize[cellToSplit] - 1; EXCHANGE( pointList[oldAlphaPosition], pointList[newAlphaPosition], temp) EXCHANGE( invPointList[pointList[oldAlphaPosition]], invPointList[pointList[newAlphaPosition]], temp) ++height; ++UpsilonStack->height; cellNumber[alpha] = height; startCell[height] = newAlphaPosition; parent[height] = cellToSplit; cellSize[height] = 1; --cellSize[cellToSplit]; /* Set the return value and return to caller. */ split.oldCellSize = cellSize[cellToSplit]; split.newCellSize = 1; return split; }
/* * Swap the cache records, e.g., when doing reverse-video. */ void swapCgs(XtermWidget xw, VTwin *cgsWin, CgsEnum dstCgsId, CgsEnum srcCgsId) { if (dstCgsId != srcCgsId) { CgsCache *dst; CgsCache *src; CgsCache tmp; if ((src = myCache(xw, cgsWin, srcCgsId)) != 0) { if ((dst = myCache(xw, cgsWin, dstCgsId)) != 0) { int srcIndex = dataIndex(src); int dstIndex = dataIndex(dst); EXCHANGE(*src, *dst, tmp); relinkData(src, dstIndex); relinkData(dst, srcIndex); } } } }
int integer_square(integer_t target, integer_t source) { bool aliased; integer_t result; if(integer_is_zero(source)) { return integer_set_unsigned_value(target, 0); } aliased = (result == source); result = aliased ? integer_create(0) : target; VERIFY(GROW(result, 2 * LENGTH(source))); SET_SIGNED_LENGTH(result, 2 * LENGTH(source)); VERIFY(digits_square(DIGITS(result), DIGITS(source), LENGTH(source))); NORMALIZE(result); // TODO: call a karatsuba routine here... if(aliased) { EXCHANGE(target, result); integer_destroy(result); } return 0; }
}; g1050_state_t *path_a_to_b; g1050_state_t *path_b_to_a; double when = 0.0; #define EXCHANGE(a,b) {a, sizeof(a) - 1, b, sizeof(b) - 1} #define RESPONSE(b) {"", 0, b, sizeof(b) - 1} #define FAST_RESPONSE(b) {NULL, -1, b, sizeof(b) - 1} #define FAST_SEND(b) {(const char *) 1, -2, b, sizeof(b) - 1} #define FAST_SEND_TCF(b) {(const char *) 2, -2, b, sizeof(b) - 1} static const struct command_response_s fax_send_test_seq[] = { EXCHANGE("ATE0\r", "ATE0\r\r\nOK\r\n"), EXCHANGE("AT+FCLASS=1\r", "\r\nOK\r\n"), EXCHANGE("ATD123456789\r", "\r\nCONNECT\r\n"), //<NSF frame> AT+FRH=3 is implied when dialing in the AT+FCLASS=1 state //RESPONSE("\xFF\x03\x10\x03"), //RESPONSE("\r\nOK\r\n"), //EXCHANGE("AT+FRH=3\r", "\r\nCONNECT\r\n"), //<CSI frame data> RESPONSE("\xFF\x03\x40\x31\x31\x31\x31\x31\x31\x31\x31\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x1e\x46\x10\x03"), RESPONSE("\r\nOK\r\n"), EXCHANGE("AT+FRH=3\r", "\r\nCONNECT\r\n"), //<DIS frame data> RESPONSE("\xFF\x13\x80\x00\xEE\xF8\x80\x80\x91\x80\x80\x80\x18\x78\x57\x10\x03"), // For audio FAXing //RESPONSE("\xFF\x13\x80\x04\xEE\xF8\x80\x80\x91\x80\x80\x80\x18\xE4\xE7\x10\x03"), // For T.38 FAXing RESPONSE("\r\nOK\r\n"), //EXCHANGE("AT+FRH=3\r", "\r\nNO CARRIER\r\n"),
int main(int argc, char** args) { if(argc>1) printf("%d, %d\n", atoi(args[1]), EXCHANGE(atoi(args[1]))); return 0; }
// MCA: ExtendedGCD int integer_gcd_extended(integer_t gcd, integer_t U, integer_t V, integer_t A, integer_t B) { integer_t a, b, u, w, v, x, q, r; INSIST(gcd != U); INSIST(gcd != V); INSIST(U != V); a = integer_create(0); b = gcd; VERIFY(integer_absolute_value(a, A)); VERIFY(integer_absolute_value(b, B)); u = U; VERIFY(integer_set_unsigned_value(u, 1)); w = integer_create(0); v = V; VERIFY(integer_set_unsigned_value(v, 0)); x = integer_create(1); q = integer_create(0); r = integer_create(0); while(!integer_is_zero(b)) { VERIFY(integer_divide(q, r, a, b)); SWAP(a, b); SWAP(b, r); VERIFY(integer_multiply(r, q, w)); VERIFY(integer_subtract(u, u, r)); SWAP(u, w); VERIFY(integer_multiply(r, q, x)); VERIFY(integer_subtract(v, v, r)); SWAP(v, x); } EXCHANGE(gcd, a); EXCHANGE(U, u); EXCHANGE(V, v); integer_destroy(q); /* gcd is passed between a, b, and r */ if(b == gcd) { integer_destroy(a); integer_destroy(r); } else if(a == gcd) { integer_destroy(b); integer_destroy(r); } else { integer_destroy(a); integer_destroy(b); } /* U and V are passed between u, w and v, x respectively */ if(u == U) { integer_destroy(w); integer_destroy(x); } else { integer_destroy(u); integer_destroy(v); } return 0; }
struct command_response_s { const char *command; int len_command; const char *response; int len_response; }; #define EXCHANGE(a,b) {a, sizeof(a) - 1, b, sizeof(b) - 1} #define RESPONSE(b) {"", 0, b, sizeof(b) - 1} #define FAST_RESPONSE(b) {NULL, -1, b, sizeof(b) - 1} #define FAST_SEND(b) {(const char *) 1, -2, b, sizeof(b) - 1} static const struct command_response_s fax_send_test_seq[] = { EXCHANGE("ATE0\r", "ATE0\r\r\nOK\r\n"), EXCHANGE("AT+FCLASS=1\r", "\r\nOK\r\n"), EXCHANGE("ATD123456789\r", "\r\nCONNECT\r\n"), //<NSF frame> AT+FRH=3 is implied when dialing in the AT+FCLASS=1 state //RESPONSE("\xFF\x03\x10\x03"), //RESPONSE("\r\nOK\r\n"), //EXCHANGE("AT+FRH=3\r", "\r\nCONNECT\r\n"), //<CSI frame data> RESPONSE("\xFF\x03\x40\x31\x31\x31\x31\x31\x31\x31\x31\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x1e\x46\x10\x03"), RESPONSE("\r\nOK\r\n"), EXCHANGE("AT+FRH=3\r", "\r\nCONNECT\r\n"), //<DIS frame data> RESPONSE("\xFF\x13\x80\x00\xEE\xF8\x80\x80\x89\x80\x80\x80\x18\x18\xB9\x10\x03"), RESPONSE("\r\nOK\r\n"), //EXCHANGE("AT+FRH=3\r", "\r\nNO CARRIER\r\n"), EXCHANGE("AT+FTH=3\r", "\r\nCONNECT\r\n"),