static void menu_cb_DrawSelectedSound (TimeSoundEditor me, EDITOR_ARGS_FORM) { EDITOR_FORM (U"Draw selected sound", nullptr) my v_form_pictureWindow (cmd); LABEL (U"", U"Sound:") BOOLEAN (U"Preserve times", my default_picture_preserveTimes ()); REAL (U"left Vertical range", my default_picture_bottom ()); REAL (U"right Vertical range", my default_picture_top ()); my v_form_pictureMargins (cmd); BOOLEAN (U"Garnish", my default_picture_garnish ()); EDITOR_OK my v_ok_pictureWindow (cmd); SET_INTEGER (U"Preserve times", my pref_picture_preserveTimes ()); SET_REAL (U"left Vertical range", my pref_picture_bottom ()); SET_REAL (U"right Vertical range", my pref_picture_top ()); my v_ok_pictureMargins (cmd); SET_INTEGER (U"Garnish", my pref_picture_garnish ()); EDITOR_DO my v_do_pictureWindow (cmd); my pref_picture_preserveTimes () = GET_INTEGER (U"Preserve times"); my pref_picture_bottom () = GET_REAL (U"left Vertical range"); my pref_picture_top () = GET_REAL (U"right Vertical range"); my v_do_pictureMargins (cmd); my pref_picture_garnish () = GET_INTEGER (U"Garnish"); if (! my d_longSound.data && ! my d_sound.data) Melder_throw (U"There is no sound to draw."); autoSound publish = my d_longSound.data ? LongSound_extractPart (my d_longSound.data, my d_startSelection, my d_endSelection, my pref_picture_preserveTimes ()) : Sound_extractPart (my d_sound.data, my d_startSelection, my d_endSelection, kSound_windowShape_RECTANGULAR, 1.0, my pref_picture_preserveTimes ()); Editor_openPraatPicture (me); Sound_draw (publish.peek(), my pictureGraphics, 0.0, 0.0, my pref_picture_bottom (), my pref_picture_top (), my pref_picture_garnish (), U"Curve"); Editor_closePraatPicture (me); EDITOR_END }
// // Ret_Query_Net: C // static void Ret_Query_Net(REBSER *port, REBREQ *sock, REBVAL *ret) { REBVAL *info = In_Object(port, STD_PORT_SCHEME, STD_SCHEME_INFO, 0); REBSER *obj; if (!info || !IS_OBJECT(info)) fail (Error_On_Port(RE_INVALID_SPEC, port, -10)); obj = Copy_Array_Shallow(VAL_OBJ_FRAME(info)); MANAGE_SERIES(obj); Val_Init_Object(ret, obj); Set_Tuple( OFV(obj, STD_NET_INFO_LOCAL_IP), cast(REBYTE*, &sock->special.net.local_ip), 4 ); Set_Tuple( OFV(obj, STD_NET_INFO_REMOTE_IP), cast(REBYTE*, &sock->special.net.remote_ip), 4 ); SET_INTEGER(OFV(obj, STD_NET_INFO_LOCAL_PORT), sock->special.net.local_port); SET_INTEGER(OFV(obj, STD_NET_INFO_REMOTE_PORT), sock->special.net.remote_port); }
*/ static void Ret_Query_Net(REBSER *port, REBREQ *sock, REBVAL *ret) /* ***********************************************************************/ { REBVAL *info = In_Object(port, STD_PORT_SCHEME, STD_SCHEME_INFO, 0); REBSER *obj; if (!info || !IS_OBJECT(info)) Trap_Port(RE_INVALID_SPEC, port, -10); obj = CLONE_OBJECT(VAL_OBJ_FRAME(info)); SET_OBJECT(ret, obj); Set_Tuple( OFV(obj, STD_NET_INFO_LOCAL_IP), cast(REBYTE*, &sock->special.net.local_ip), 4 ); Set_Tuple( OFV(obj, STD_NET_INFO_REMOTE_IP), cast(REBYTE*, &sock->special.net.remote_ip), 4 ); SET_INTEGER(OFV(obj, STD_NET_INFO_LOCAL_PORT), sock->special.net.local_port); SET_INTEGER(OFV(obj, STD_NET_INFO_REMOTE_PORT), sock->special.net.remote_port); }
LispObject MakeInteger(int value) { LispObject o; SET_INTEGER(o, value); return o; }
static void menu_cb_print (EDITOR_ARGS) { EDITOR_IAM (HyperPage); EDITOR_FORM (L"Print", 0) SENTENCE (L"Left or inside header", L"") SENTENCE (L"Middle header", L"") LABEL (L"", L"Right or outside header:") TEXTFIELD (L"Right or outside header", L"") SENTENCE (L"Left or inside footer", L"") SENTENCE (L"Middle footer", L"") SENTENCE (L"Right or outside footer", L"") BOOLEAN (L"Mirror even/odd headers", TRUE) INTEGER (L"First page number", L"0 (= no page numbers)") EDITOR_OK my v_defaultHeaders (cmd); if (my d_printingPageNumber) SET_INTEGER (L"First page number", my d_printingPageNumber + 1) EDITOR_DO my insideHeader = GET_STRING (L"Left or inside header"); my middleHeader = GET_STRING (L"Middle header"); my outsideHeader = GET_STRING (L"Right or outside header"); my insideFooter = GET_STRING (L"Left or inside footer"); my middleFooter = GET_STRING (L"Middle footer"); my outsideFooter = GET_STRING (L"Right or outside footer"); my mirror = GET_INTEGER (L"Mirror even/odd headers"); my d_printingPageNumber = GET_INTEGER (L"First page number"); Printer_print (print, me); EDITOR_END }
*/ void Ret_Query_File(REBSER *port, REBREQ *file, REBVAL *ret) /* ** Query file and set RET value to resulting STD_FILE_INFO object. ** ***********************************************************************/ { REBVAL *info = In_Object(port, STD_PORT_SCHEME, STD_SCHEME_INFO, 0); REBSER *obj; REBSER *ser; if (!info || !IS_OBJECT(info)) Trap_Port(RE_INVALID_SPEC, port, -10); obj = CLONE_OBJECT(VAL_OBJ_FRAME(info)); SET_OBJECT(ret, obj); Init_Word_Unbound( OFV(obj, STD_FILE_INFO_TYPE), REB_WORD, GET_FLAG(file->modes, RFM_DIR) ? SYM_DIR : SYM_FILE ); SET_INTEGER(OFV(obj, STD_FILE_INFO_SIZE), file->special.file.size); Set_File_Date(file, OFV(obj, STD_FILE_INFO_DATE)); ser = To_REBOL_Path(file->special.file.path, 0, OS_WIDE, 0); Set_Series(REB_FILE, OFV(obj, STD_FILE_INFO_NAME), ser); }
*/ ATTRIBUTE_NO_RETURN static void Error_Compression(const z_stream *strm, int ret) /* ** Zlib gives back string error messages. We use them or fall ** back on the integer code if there is no message. ** ***********************************************************************/ { REBVAL arg; if (ret == Z_MEM_ERROR) { // We do not technically know the amount of memory that zlib asked // for and did not get. Hence categorizing it as an "out of memory" // error might be less useful than leaving as a compression error, // but that is what the old code here historically did. raise Error_No_Memory(0); } if (strm->msg) Val_Init_String( &arg, Copy_Bytes(cb_cast(strm->msg), strlen(strm->msg)) ); else SET_INTEGER(&arg, ret); Error_1(RE_BAD_COMPRESSION, &arg); }
*/ REBSER *Decompress(REBSER *input, REBCNT index, REBINT len, REBCNT limit, REBFLG use_crc) /* ** Decompress a binary (only). ** ***********************************************************************/ { REBCNT size; REBSER *output; REBINT err; if (len < 0 || (index + len > BIN_LEN(input))) len = BIN_LEN(input) - index; // Get the size from the end and make the output buffer that size. if (len <= 4) Trap0(RE_PAST_END); // !!! better msg needed size = Bytes_To_Long(BIN_SKIP(input, len) - 4); if (limit && size > limit) Trap_Num(RE_SIZE_LIMIT, size); output = Make_Binary(size + 20); // (Why 20 extra? -CS) //DISABLE_GC; err = Z_uncompress(BIN_HEAD(output), (uLongf*)&size, BIN_HEAD(input) + index, len, use_crc); if (err) { if (PG_Boot_Phase < 2) return 0; if (err == Z_MEM_ERROR) Trap0(RE_NO_MEMORY); SET_INTEGER(DS_RETURN, err); Trap1(RE_BAD_PRESS, DS_RETURN); //!!!provide error string descriptions } SET_STR_END(output, size); SERIES_TAIL(output) = size; //ENABLE_GC; return output; }
*/ REBSER *Make_Error(REBINT code, REBVAL *arg1, REBVAL *arg2, REBVAL *arg3) /* ** Create and init a new error object. ** ***********************************************************************/ { REBSER *err; // Error object ERROR_OBJ *error; // Error object values if (PG_Boot_Phase < BOOT_ERRORS) Crash(RP_EARLY_ERROR, code); // Not far enough! // Make a copy of the error object template: err = CLONE_OBJECT(VAL_OBJ_FRAME(ROOT_ERROBJ)); error = ERR_VALUES(err); // Set error number: SET_INTEGER(&error->code, (REBINT)code); Set_Error_Type(error); // Set error argument values: if (arg1) error->arg1 = *arg1; if (arg2) error->arg2 = *arg2; if (arg3) error->arg3 = *arg3; // Set backtrace and location information: if (DSF > 0) { // Where (what function) is the error: Set_Block(&error->where, Make_Backtrace(0)); // Nearby location of the error (in block being evaluated): error->nearest = *DSF_BACK(DSF); } return err; }
REBVAL *N_watch(REBFRM *frame, REBVAL **inter_block) { WatchVar = Get_Word(FRM_ARG1(frame)); Watcher = VAL_SERIES(WatchVar); SET_INTEGER(FRM_ARG1(frame), 0); return Nothing; }
// // Pick_Vector: C // void Pick_Vector(REBVAL *out, const REBVAL *value, const REBVAL *picker) { REBSER *vect = VAL_SERIES(value); REBINT n; if (IS_INTEGER(picker) || IS_DECIMAL(picker)) n = Int32(picker); else fail (Error_Invalid_Arg(picker)); n += VAL_INDEX(value); if (n <= 0 || cast(REBCNT, n) > SER_LEN(vect)) { SET_VOID(out); // out of range of vector data return; } REBYTE *vp = SER_DATA_RAW(vect); REBINT bits = VECT_TYPE(vect); if (bits < VTSF08) SET_INTEGER(out, get_vect(bits, vp, n - 1)); // 64-bit else { VAL_RESET_HEADER(out, REB_DECIMAL); INIT_DECIMAL_BITS(out, get_vect(bits, vp, n - 1)); // 64-bit } }
*/ REBINT PD_String(REBPVS *pvs) /* ***********************************************************************/ { REBVAL *data = pvs->value; REBVAL *val = pvs->setval; REBINT n = 0; REBCNT i; REBINT c; REBSER *ser = VAL_SERIES(data); if (IS_INTEGER(pvs->select)) { n = Int32(pvs->select) + VAL_INDEX(data) - 1; } else return PE_BAD_SELECT; if (val == 0) { if (n < 0 || (REBCNT)n >= SERIES_TAIL(ser)) return PE_NONE; if (IS_BINARY(data)) { SET_INTEGER(pvs->store, *BIN_SKIP(ser, n)); } else { SET_CHAR(pvs->store, GET_ANY_CHAR(ser, n)); } return PE_USE; } if (n < 0 || (REBCNT)n >= SERIES_TAIL(ser)) return PE_BAD_RANGE; if (IS_CHAR(val)) { c = VAL_CHAR(val); if (c > MAX_CHAR) return PE_BAD_SET; } else if (IS_INTEGER(val)) { c = Int32(val); if (c > MAX_CHAR || c < 0) return PE_BAD_SET; if (IS_BINARY(data)) { // special case for binary if (c > 0xff) Trap_Range(val); BIN_HEAD(ser)[n] = (REBYTE)c; return PE_OK; } } else if (ANY_BINSTR(val)) { i = VAL_INDEX(val); if (i >= VAL_TAIL(val)) return PE_BAD_SET; c = GET_ANY_CHAR(VAL_SERIES(val), i); } else return PE_BAD_SELECT; TRAP_PROTECT(ser); if (BYTE_SIZE(ser) && c > 0xff) Widen_String(ser); SET_ANY_CHAR(ser, n, c); return PE_OK; }
// // Back_Scan_UTF8_Char: C // // Converts a single UTF8 code-point and returns the position *at the // the last byte of the character's data*. (This differs from the usual // `Scan_XXX` interface of returning the position after the scanned // element, ready to read the next one.) // // The peculiar interface is useful in loops that are processing // ordinary ASCII chars directly -as well- as UTF8 ones. The loop can // do a single byte pointer increment after both kinds of // elements, avoiding the need to call any kind of `Scan_Ascii()`: // // for (; len > 0; bp++, len--) { // if (*bp < 0x80) { // // do ASCII stuff... // } // else { // REBUNI uni; // bp = Back_Scan_UTF8_Char(&uni, bp, &len); // // do UNICODE stuff... // } // } // // The third parameter is an optional length that will be decremented by // the number of "extra" bytes the UTF8 has beyond a single byte character. // This allows for decrement-style loops such as the above. // // Though the machinery can decode a UTF32 32-bit codepoint, the interface // uses a 16-bit REBUNI (due to that being all that Rebol supports at this // time). If a codepoint that won't fit in 16-bits is found, it will raise // an error vs. return NULL. This makes it clear that the problem is not // with the data itself being malformed (the usual assumption of callers) // but rather a limit of the implementation. // // Prescans source for null, and will not return code point 0. // // If failure due to insufficient data or malformed bytes, then NULL is // returned (len is not advanced). // const REBYTE *Back_Scan_UTF8_Char(REBUNI *out, const REBYTE *bp, REBCNT *len) { const UTF8 *source = bp; UTF32 ch = 0; REBCNT trail = trailingBytesForUTF8[*source]; // Check that we have enough valid source bytes: if (len) { if (trail + 1 > *len) return NULL; } else if (trail != 0) { do { if (source[trail] < 0x80) return NULL; } while (--trail != 0); trail = trailingBytesForUTF8[*source]; } // Do this check whether lenient or strict: // if (!isLegalUTF8(source, slen+1)) return 0; switch (trail) { case 5: ch += *source++; ch <<= 6; case 4: ch += *source++; ch <<= 6; case 3: ch += *source++; ch <<= 6; case 2: ch += *source++; ch <<= 6; case 1: ch += *source++; ch <<= 6; case 0: ch += *source++; } ch -= offsetsFromUTF8[trail]; // UTF-16 surrogate values are illegal in UTF-32, and anything // over Plane 17 (> 0x10FFFF) is illegal. if (ch > UNI_MAX_LEGAL_UTF32) return NULL; if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END) return NULL; if (len) *len -= trail; // !!! Original implementation used 0 as a return value to indicate a // decoding failure. However, 0 is a legal UTF8 codepoint, and also // Rebol strings are able to store NUL characters (they track a length // and are not zero-terminated.) Should this be legal? assert(ch != 0); if (ch == 0) return NULL; if (ch > 0xFFFF) { // !!! Not currently supported. REBVAL num; VAL_INIT_WRITABLE_DEBUG(&num); SET_INTEGER(&num, ch); fail (Error(RE_CODEPOINT_TOO_HIGH, &num)); } *out = ch; return bp + trail; }
static void menu_cb_fontSize (EDITOR_ARGS) { EDITOR_IAM (HyperPage); EDITOR_FORM (L"Font size", 0) NATURAL (L"Font size (points)", L"12") EDITOR_OK SET_INTEGER (L"Font size", my fontSize) EDITOR_DO setFontSize (me, GET_INTEGER (L"Font size")); EDITOR_END }
static void menu_cb_selectFormantOrBandwidth (FormantGridEditor me, EDITOR_ARGS_FORM) { EDITOR_FORM (U"Select formant or bandwidth", nullptr) NATURAL (U"Formant number", U"1") EDITOR_OK SET_INTEGER (U"Formant number", my selectedFormant) EDITOR_DO selectFormantOrBandwidth (me, GET_INTEGER (U"Formant number")); FunctionEditor_redraw (me); EDITOR_END }
int Printer_postScriptSettings (void) { static UiForm *dia; if (dia == NULL) { UiForm::UiField *radio; dia = new UiForm (theCurrentPraatApplication -> topShell, L"PostScript settings", DO_Printer_postScriptSettings, NULL, L"PostScript settings...", L"PostScript settings..."); #if defined (_WIN32) || defined (macintosh) BOOLEAN (L"Allow direct PostScript", TRUE); #endif RADIO_ENUM (L"Grey resolution", kGraphicsPostscript_spots, DEFAULT) #if defined (UNIX) RADIO_ENUM (L"Paper size", kGraphicsPostscript_paperSize, DEFAULT); RADIO_ENUM (L"Orientation", kGraphicsPostscript_orientation, DEFAULT); POSITIVE (L"Magnification", L"1.0"); LABEL (L"label", L"Print command:"); #if defined (linux) TEXTFIELD (L"printCommand", L"lpr %s"); #else TEXTFIELD (L"printCommand", L"lp -c %s"); #endif #endif RADIO_ENUM (L"Font choice strategy", kGraphicsPostscript_fontChoiceStrategy, DEFAULT); #if defined (macintosh) BOOLEAN (L"EPS files include preview", TRUE); #endif dia->finish (); } #if defined (_WIN32) || defined (macintosh) SET_INTEGER (L"Allow direct PostScript", thePrinter. allowDirectPostScript); #endif SET_ENUM (L"Grey resolution", kGraphicsPostscript_spots, thePrinter. spots); #if defined (UNIX) SET_ENUM (L"Paper size", kGraphicsPostscript_paperSize, thePrinter. paperSize); SET_ENUM (L"Orientation", kGraphicsPostscript_orientation, thePrinter. orientation); SET_REAL (L"Magnification", thePrinter. magnification); SET_STRING (L"printCommand", Site_getPrintCommand ()); #endif SET_ENUM (L"Font choice strategy", kGraphicsPostscript_fontChoiceStrategy, thePrinter. fontChoiceStrategy); #if defined (macintosh) SET_INTEGER (L"EPS files include preview", thePrinter. epsFilesHavePreview); #endif dia->do_ (false); return 1; }
*/ REBSER *Gob_To_Block(REBGOB *gob) /* ** Used by MOLD to create a block. ** ***********************************************************************/ { REBSER *ser = Make_Block(10); REBVAL *val; REBINT words[6] = {SYM_OFFSET, SYM_SIZE, SYM_ALPHA, 0}; REBVAL *vals[6]; REBINT n = 0; REBVAL *val1; REBCNT sym; for (n = 0; words[n]; n++) { val = Append_Value(ser); Init_Word(val, words[n]); VAL_SET(val, REB_SET_WORD); vals[n] = Append_Value(ser); } SET_PAIR(vals[0], GOB_X(gob), GOB_Y(gob)); SET_PAIR(vals[1], GOB_W(gob), GOB_H(gob)); SET_INTEGER(vals[2], GOB_ALPHA(gob)); if (!GOB_TYPE(gob)) return ser; if (GOB_CONTENT(gob)) { val1 = Append_Value(ser); val = Append_Value(ser); switch (GOB_TYPE(gob)) { case GOBT_COLOR: sym = SYM_COLOR; break; case GOBT_IMAGE: sym = SYM_IMAGE; break; case GOBT_STRING: case GOBT_TEXT: sym = SYM_TEXT; break; case GOBT_DRAW: sym = SYM_DRAW; break; case GOBT_EFFECT: sym = SYM_EFFECT; break; } Init_Word(val1, sym); VAL_SET(val1, REB_SET_WORD); Get_GOB_Var(gob, val1, val); } return ser; }
static void menu_cb_selectFormantOrBandwidth (EDITOR_ARGS) { EDITOR_IAM (FormantGridEditor); EDITOR_FORM (L"Select formant or bandwidth", 0) NATURAL (L"Formant number", L"1") EDITOR_OK SET_INTEGER (L"Formant number", my selectedFormant) EDITOR_DO selectFormantOrBandwidth (me, GET_INTEGER (L"Formant number")); FunctionEditor_redraw (me); EDITOR_END }
static void menu_cb_preferences (TableEditor me, EDITOR_ARGS_FORM) { EDITOR_FORM (U"TableEditor preferences", nullptr); OPTIONMENU (U"The symbols %#_^ in labels", my default_useTextStyles () + 1) OPTION (U"are shown as typed") OPTION (U"mean italic/bold/sub/super") EDITOR_OK SET_INTEGER (U"The symbols %#_^ in labels", my p_useTextStyles + 1) EDITOR_DO my pref_useTextStyles () = my p_useTextStyles = GET_INTEGER (U"The symbols %#_^ in labels") - 1; Graphics_updateWs (my graphics.get()); EDITOR_END }
// // Destroy_External_Storage: C // // Destroy the external storage pointed by `->data` by calling the routine // `free_func` if it's not NULL // // out Result // ser The series // free_func A routine to free the storage, if it's NULL, only mark the // external storage non-accessible // REB_R Destroy_External_Storage(REBVAL *out, REBSER *ser, REBVAL *free_func) { SET_VOID(out); if (!GET_SER_FLAG(ser, SERIES_FLAG_EXTERNAL)) { fail (Error(RE_NO_EXTERNAL_STORAGE)); } if (!GET_SER_FLAG(ser, SERIES_FLAG_ACCESSIBLE)) { REBVAL i; SET_INTEGER(&i, cast(REBUPT, SER_DATA_RAW(ser))); fail (Error(RE_ALREADY_DESTROYED, &i)); } CLEAR_SER_FLAG(ser, SERIES_FLAG_ACCESSIBLE); if (free_func) { REBVAL safe; REBARR *array; REBVAL *elem; REBOOL threw; array = Make_Array(2); MANAGE_ARRAY(array); PUSH_GUARD_ARRAY(array); elem = Alloc_Tail_Array(array); *elem = *free_func; elem = Alloc_Tail_Array(array); SET_INTEGER(elem, cast(REBUPT, SER_DATA_RAW(ser))); threw = Do_At_Throws(&safe, array, 0, SPECIFIED); // 2 non-relative val DROP_GUARD_ARRAY(array); if (threw) return R_OUT_IS_THROWN; } return R_OUT; }
*/ REBSER *Compress(REBSER *input, REBINT index, REBINT len, REBFLG use_crc) /* ** Compress a binary (only). ** data ** /part ** length ** /crc32 ** ** Note: If the file length is "small", it can't overrun on ** compression too much so we use our magic numbers; otherwise, ** we'll just be safe by a percentage of the file size. This may ** be a bit much, though. ** ***********************************************************************/ { // NOTE: The use_crc flag is not present in Zlib 1.2.8 // Instead, compress's fifth paramter is the compression level // It can be a value from 1 to 9, or Z_DEFAULT_COMPRESSION if you // want it to pick what the library author considers the "worth it" // tradeoff of time to generally suggest. uLongf size; REBSER *output; REBINT err; REBYTE out_size[sizeof(REBCNT)]; if (len < 0) Trap_DEAD_END(RE_PAST_END); // !!! better msg needed size = len + (len > STERLINGS_MAGIC_NUMBER ? len / 10 + 12 : STERLINGS_MAGIC_FIX); output = Make_Binary(size); //DISABLE_GC; // !!! why?? // dest, dest-len, src, src-len, level err = z_compress2(BIN_HEAD(output), &size, BIN_HEAD(input) + index, len, Z_DEFAULT_COMPRESSION); if (err) { REBVAL arg; if (err == Z_MEM_ERROR) Trap_DEAD_END(RE_NO_MEMORY); SET_INTEGER(&arg, err); Trap1_DEAD_END(RE_BAD_PRESS, &arg); //!!!provide error string descriptions } SET_STR_END(output, size); SERIES_TAIL(output) = size; REBCNT_To_Bytes(out_size, (REBCNT)len); // Tag the size to the end. Append_Series(output, (REBYTE*)out_size, sizeof(REBCNT)); if (SERIES_AVAIL(output) > 1024) // Is there wasted space? output = Copy_Series(output); // Trim it down if too big. !!! Revisit this based on mem alloc alg. //ENABLE_GC; return output; }
// // PD_Tuple: C // // Implements PATH and SET_PATH for tuple. // Sets DS_TOP if found. Always returns 0. // REBINT PD_Tuple(REBPVS *pvs) { const REBVAL *setval; REBINT n; REBINT i; REBYTE *dat; REBINT len; dat = VAL_TUPLE(pvs->value); len = VAL_TUPLE_LEN(pvs->value); if (len < 3) { len = 3; } n = Get_Num_From_Arg(pvs->selector); if ((setval = pvs->opt_setval)) { if (n <= 0 || n > cast(REBINT, MAX_TUPLE)) fail (Error_Bad_Path_Select(pvs)); if (IS_INTEGER(setval) || IS_DECIMAL(setval)) i = Int32(setval); else if (IS_BLANK(setval)) { n--; CLEAR(dat + n, MAX_TUPLE - n); VAL_TUPLE_LEN(pvs->value) = n; return PE_OK; } else fail (Error_Bad_Path_Set(pvs)); if (i < 0) i = 0; else if (i > 255) i = 255; dat[n - 1] = i; if (n > len) VAL_TUPLE_LEN(pvs->value) = n; return PE_OK; } else { if (n > 0 && n <= len) { SET_INTEGER(pvs->store, dat[n - 1]); return PE_USE_STORE; } else return PE_NONE; } }
static void menu_cb_font (EDITOR_ARGS) { EDITOR_IAM (HyperPage); EDITOR_FORM (L"Font", 0) RADIO (L"Font", 1) RADIOBUTTON (L"Times") RADIOBUTTON (L"Helvetica") EDITOR_OK SET_INTEGER (L"Font", my font == kGraphics_font_TIMES ? 1 : my font == kGraphics_font_HELVETICA ? 2 : my font == kGraphics_font_PALATINO ? 3 : 1); EDITOR_DO int font = GET_INTEGER (L"Font"); prefs_font = my font = font == 1 ? kGraphics_font_TIMES : kGraphics_font_HELVETICA; if (my g) Graphics_updateWs (my g); EDITOR_END }
*/ REBSER *Compress(REBSER *input, REBINT index, REBINT len, REBFLG use_crc) /* ** Compress a binary (only). ** data ** /part ** length ** /crc32 ** ** Note: If the file length is "small", it can't overrun on ** compression too much so we use our magic numbers; otherwise, ** we'll just be safe by a percentage of the file size. This may ** be a bit much, though. ** ***********************************************************************/ { REBCNT size; REBSER *output; REBINT err; REBYTE out_size[4]; if (len < 0) Trap0(RE_PAST_END); // !!! better msg needed size = len + (len > STERLINGS_MAGIC_NUMBER ? len / 10 + 12 : STERLINGS_MAGIC_FIX); output = Make_Binary(size); //DISABLE_GC; // !!! why?? // dest, dest-len, src, src-len, level err = Z_compress2(BIN_HEAD(output), (uLongf*)&size, BIN_HEAD(input) + index, len, use_crc); if (err) { if (err == Z_MEM_ERROR) Trap0(RE_NO_MEMORY); SET_INTEGER(DS_RETURN, err); Trap1(RE_BAD_PRESS, DS_RETURN); //!!!provide error string descriptions } SET_STR_END(output, size); SERIES_TAIL(output) = size; Long_To_Bytes(out_size, (REBCNT)len); // Tag the size to the end. Append_Series(output, (REBYTE*)out_size, 4); if (SERIES_AVAIL(output) > 1024) // Is there wasted space? output = Copy_Series(output); // Trim it down if too big. !!! Revisit this based on mem alloc alg. //ENABLE_GC; return output; }
*/ REBINT PD_Tuple(REBPVS *pvs) /* ** Implements PATH and SET_PATH for tuple. ** Sets DS_TOP if found. Always returns 0. ** ***********************************************************************/ { REBVAL *val; REBINT n; REBINT i; REBYTE *dat; REBINT len; dat = VAL_TUPLE(pvs->value); len = VAL_TUPLE_LEN(pvs->value); if (len < 3) len = 3; n = Get_Num_Arg(pvs->select); if (NZ(val = pvs->setval)) { if (n <= 0 || n > MAX_TUPLE) return PE_BAD_SELECT; if (IS_INTEGER(val) || IS_DECIMAL(val)) i = Int32(val); else if (IS_NONE(val)) { n--; CLEAR(dat+n, MAX_TUPLE-n); VAL_TUPLE_LEN(pvs->value) = n; return PE_OK; } else return PE_BAD_SET; if (i < 0) i = 0; else if (i > 255) i = 255; dat[n-1] = i; if (n > len) VAL_TUPLE_LEN(pvs->value) = n; return PE_OK; } else { if (n > 0 && n <= len) { SET_INTEGER(pvs->store, dat[n-1]); return PE_USE; } else return PE_NONE; } }
*/ REBSER *Decompress(const REBYTE *data, REBCNT len, REBCNT limit, REBFLG use_crc) /* ** Decompress a binary (only). ** ** Rebol's compress/decompress functions store an extra length ** at the tail of the data, to double-check the zlib result ** ***********************************************************************/ { // NOTE: The use_crc flag is not present in Zlib 1.2.8 // There is no fifth parameter to uncompress matching the fifth to compress uLongf size; REBSER *output; REBINT err; // Get the size from the end and make the output buffer that size. if (len <= 4) Trap_DEAD_END(RE_PAST_END); // !!! better msg needed size = Bytes_To_REBCNT(data + len - sizeof(REBCNT)); // NOTE: You can hit this if you 'make prep' without doing a full rebuild // (If you 'make clean' and build again and this goes away, it was that) if (limit && size > limit) Trap_Num(RE_SIZE_LIMIT, size); output = Make_Binary(size); //DISABLE_GC; err = z_uncompress(BIN_HEAD(output), &size, data, len); if (err) { REBVAL arg; if (PG_Boot_Phase < 2) return 0; if (err == Z_MEM_ERROR) Trap_DEAD_END(RE_NO_MEMORY); SET_INTEGER(&arg, err); Trap1_DEAD_END(RE_BAD_PRESS, &arg); //!!!provide error string descriptions } SET_STR_END(output, size); SERIES_TAIL(output) = size; //ENABLE_GC; return output; }
static void menu_cb_ExtractSelectedSound_windowed (TimeSoundEditor me, EDITOR_ARGS_FORM) { EDITOR_FORM (U"Extract selected sound (windowed)", nullptr) WORD (U"Name", U"slice") OPTIONMENU_ENUM (U"Window shape", kSound_windowShape, my default_extract_windowShape ()) POSITIVE (U"Relative width", my default_extract_relativeWidth ()) BOOLEAN (U"Preserve times", my default_extract_preserveTimes ()) EDITOR_OK SET_ENUM (U"Window shape", kSound_windowShape, my pref_extract_windowShape ()) SET_REAL (U"Relative width", my pref_extract_relativeWidth ()) SET_INTEGER (U"Preserve times", my pref_extract_preserveTimes ()) EDITOR_DO Sound sound = my d_sound.data; Melder_assert (sound); my pref_extract_windowShape () = GET_ENUM (kSound_windowShape, U"Window shape"); my pref_extract_relativeWidth () = GET_REAL (U"Relative width"); my pref_extract_preserveTimes () = GET_INTEGER (U"Preserve times"); autoSound extract = Sound_extractPart (sound, my d_startSelection, my d_endSelection, my pref_extract_windowShape (), my pref_extract_relativeWidth (), my pref_extract_preserveTimes ()); Thing_setName (extract.peek(), GET_STRING (U"Name")); Editor_broadcastPublication (me, extract.transfer()); EDITOR_END }
*/ REBSER *Struct_To_Block(const REBSTU *stu) /* ** Used by MOLD to create a block. ** ***********************************************************************/ { REBSER *ser = Make_Array(10); struct Struct_Field *field = (struct Struct_Field*) SERIES_DATA(stu->fields); REBCNT i; // We are building a recursive structure. So if we did not hand each // sub-series over to the GC then a single Free_Series() would not know // how to free them all. There would have to be a specialized walk to // free the resulting structure. Hence, don't invoke the GC until the // root series being returned is done being used or is safe from GC! MANAGE_SERIES(ser); for(i = 0; i < SERIES_TAIL(stu->fields); i ++, field ++) { REBVAL *val = NULL; REBVAL *type_blk = NULL; /* required field name */ val = Alloc_Tail_Array(ser); Val_Init_Word_Unbound(val, REB_SET_WORD, field->sym); /* required type */ type_blk = Alloc_Tail_Array(ser); Val_Init_Block(type_blk, Make_Array(1)); val = Alloc_Tail_Array(VAL_SERIES(type_blk)); if (field->type == STRUCT_TYPE_STRUCT) { REBVAL *nested = NULL; DS_PUSH_NONE; nested = DS_TOP; Val_Init_Word_Unbound(val, REB_WORD, SYM_STRUCT_TYPE); get_scalar(stu, field, 0, nested); val = Alloc_Tail_Array(VAL_SERIES(type_blk)); Val_Init_Block(val, Struct_To_Block(&VAL_STRUCT(nested))); DS_DROP; } else Val_Init_Word_Unbound(val, REB_WORD, type_to_sym[field->type]); /* optional dimension */ if (field->dimension > 1) { REBSER *dim = Make_Array(1); REBVAL *dv = NULL; val = Alloc_Tail_Array(VAL_SERIES(type_blk)); Val_Init_Block(val, dim); dv = Alloc_Tail_Array(dim); SET_INTEGER(dv, field->dimension); } /* optional initialization */ if (field->dimension > 1) { REBSER *dim = Make_Array(1); REBCNT n = 0; val = Alloc_Tail_Array(ser); Val_Init_Block(val, dim); for (n = 0; n < field->dimension; n ++) { REBVAL *dv = Alloc_Tail_Array(dim); get_scalar(stu, field, n, dv); } } else { val = Alloc_Tail_Array(ser); get_scalar(stu, field, 0, val); } } return ser; }
*/ REBINT PD_Time(REBPVS *pvs) /* ***********************************************************************/ { REBVAL *val; REBINT i; REBINT n; REBDEC f; REB_TIMEF tf; if (IS_WORD(pvs->select)) { switch (VAL_WORD_CANON(pvs->select)) { case SYM_HOUR: i = 0; break; case SYM_MINUTE: i = 1; break; case SYM_SECOND: i = 2; break; default: return PE_BAD_SELECT; } } else if (IS_INTEGER(pvs->select)) i = VAL_INT32(pvs->select) - 1; else return PE_BAD_SELECT; Split_Time(VAL_TIME(pvs->value), &tf); // loses sign if (!(val = pvs->setval)) { val = pvs->store; switch(i) { case 0: // hours SET_INTEGER(val, tf.h); break; case 1: SET_INTEGER(val, tf.m); break; case 2: if (tf.n == 0) SET_INTEGER(val, tf.s); else SET_DECIMAL(val, (REBDEC)tf.s + (tf.n * NANO)); break; default: return PE_NONE; } return PE_USE; } else { if (IS_INTEGER(val) || IS_DECIMAL(val)) n = Int32s(val, 0); else if (IS_NONE(val)) n = 0; else return PE_BAD_SET; switch(i) { case 0: tf.h = n; break; case 1: tf.m = n; break; case 2: if (IS_DECIMAL(val)) { f = VAL_DECIMAL(val); if (f < 0.0) Trap_Range_DEAD_END(val); tf.s = (REBINT)f; tf.n = (REBINT)((f - tf.s) * SEC_SEC); } else { tf.s = n; tf.n = 0; } break; default: return PE_BAD_SELECT; } VAL_TIME(pvs->value) = Join_Time(&tf, FALSE); return PE_OK; } }
static REBOOL get_scalar(const REBSTU *stu, const struct Struct_Field *field, REBCNT n, /* element index, starting from 0 */ REBVAL *val) { REBYTE *data = SERIES_SKIP(STRUCT_DATA_BIN(stu), STRUCT_OFFSET(stu) + field->offset + n * field->size); switch (field->type) { case STRUCT_TYPE_UINT8: SET_INTEGER(val, *(u8*)data); break; case STRUCT_TYPE_INT8: SET_INTEGER(val, *(i8*)data); break; case STRUCT_TYPE_UINT16: SET_INTEGER(val, *(u16*)data); break; case STRUCT_TYPE_INT16: SET_INTEGER(val, *(i8*)data); break; case STRUCT_TYPE_UINT32: SET_INTEGER(val, *(u32*)data); break; case STRUCT_TYPE_INT32: SET_INTEGER(val, *(i32*)data); break; case STRUCT_TYPE_UINT64: SET_INTEGER(val, *(u64*)data); break; case STRUCT_TYPE_INT64: SET_INTEGER(val, *(i64*)data); break; case STRUCT_TYPE_FLOAT: SET_DECIMAL(val, *(float*)data); break; case STRUCT_TYPE_DOUBLE: SET_DECIMAL(val, *(double*)data); break; case STRUCT_TYPE_POINTER: SET_INTEGER(val, cast(REBUPT, *cast(void**, data))); break; case STRUCT_TYPE_STRUCT: { SET_TYPE(val, REB_STRUCT); VAL_STRUCT_FIELDS(val) = field->fields; VAL_STRUCT_SPEC(val) = field->spec; VAL_STRUCT_DATA(val) = Make_Series( 1, sizeof(struct Struct_Data), MKS_NONE ); MANAGE_SERIES(VAL_STRUCT_DATA(val)); VAL_STRUCT_DATA_BIN(val) = STRUCT_DATA_BIN(stu); VAL_STRUCT_OFFSET(val) = data - SERIES_DATA(VAL_STRUCT_DATA_BIN(val)); VAL_STRUCT_LEN(val) = field->size; } break; case STRUCT_TYPE_REBVAL: memcpy(val, data, sizeof(REBVAL)); break; default: /* should never be here */ return FALSE; } return TRUE; }