static void b_magickCompressImage1(task *tsk, pntr *argstack) { /* pointers to the parameters */ pntr val1 = argstack[4]; // imageFile pntr val2 = argstack[3]; // outputImage pntr val3 = argstack[2]; // format pntr val4 = argstack[1]; // compressionType pntr val5 = argstack[0]; // compressionRate int badtype; /* the result value to be return */ int result; char *imageFile; char *outputImage; char *format; int compressionType; double compressionRate; /* Check validity of each parameter */ CHECK_ARG(4, CELL_CONS); CHECK_ARG(3, CELL_CONS); CHECK_ARG(2, CELL_CONS); CHECK_ARG(1, CELL_NUMBER); CHECK_ARG(0, CELL_NUMBER); /* Initialize all arguments for this method */ if( (badtype = array_to_string(val1, &imageFile)) > 0) { set_error(tsk, "string: argument is not a string (contains non-char: %s)", cell_types[badtype]); return; } if( (badtype = array_to_string(val2, &outputImage)) > 0) { set_error(tsk, "string: argument is not a string (contains non-char: %s)", cell_types[badtype]); return; } if( (badtype = array_to_string(val3, &format)) > 0) { set_error(tsk, "string: argument is not a string (contains non-char: %s)", cell_types[badtype]); return; } compressionType = pntrdouble(val4); compressionRate = pntrdouble(val5); /* Call the method and get the return value */ result = magickCompressImage(imageFile, outputImage, format, compressionType, compressionRate); /* Translate the resultant pntr to be return */ pntr p_result; set_pntrdouble(p_result, result); /* set the return value */ argstack[0] = p_result; }
static void b_magickResizeImage1(task *tsk, pntr *argstack) { /* pointers to the parameters */ pntr val1 = argstack[5]; // imageFile pntr val2 = argstack[4]; // outputImage pntr val3 = argstack[3]; // columns pntr val4 = argstack[2]; // rows pntr val5 = argstack[1]; // magickFilter pntr val6 = argstack[0]; // blur int badtype; /* the result value to be return */ int result; char *imageFile; char *outputImage; int columns; int rows; int magickFilter; double blur; /* Check validity of each parameter */ CHECK_ARG(5, CELL_CONS); CHECK_ARG(4, CELL_CONS); CHECK_ARG(3, CELL_NUMBER); CHECK_ARG(2, CELL_NUMBER); CHECK_ARG(1, CELL_NUMBER); CHECK_ARG(0, CELL_NUMBER); /* Initialize all arguments for this method */ if( (badtype = array_to_string(val1, &imageFile)) > 0) { set_error(tsk, "string: argument is not a string (contains non-char: %s)", cell_types[badtype]); return; } if( (badtype = array_to_string(val2, &outputImage)) > 0) { set_error(tsk, "string: argument is not a string (contains non-char: %s)", cell_types[badtype]); return; } columns = pntrdouble(val3); rows = pntrdouble(val4); magickFilter = pntrdouble(val5); blur = pntrdouble(val6); /* Call the method and get the return value */ result = magickResizeImage(imageFile, outputImage, columns, rows, magickFilter, blur); /* Translate the resultant pntr to be return */ pntr p_result; set_pntrdouble(p_result, result); /* set the return value */ argstack[0] = p_result; }
static void b_magickUnsharpMaskImage1(task *tsk, pntr *argstack) { /* pointers to the parameters */ pntr val1 = argstack[5]; // imageFile pntr val2 = argstack[4]; // outputImage pntr val3 = argstack[3]; // radius pntr val4 = argstack[2]; // sigma pntr val5 = argstack[1]; // amount pntr val6 = argstack[0]; // threshold int badtype; /* the result value to be return */ int result; char *imageFile; char *outputImage; double radius; double sigma; double amount; double threshold; /* Check validity of each parameter */ CHECK_ARG(5, CELL_CONS); CHECK_ARG(4, CELL_CONS); CHECK_ARG(3, CELL_NUMBER); CHECK_ARG(2, CELL_NUMBER); CHECK_ARG(1, CELL_NUMBER); CHECK_ARG(0, CELL_NUMBER); /* Initialize all arguments for this method */ if( (badtype = array_to_string(val1, &imageFile)) > 0) { set_error(tsk, "string: argument is not a string (contains non-char: %s)", cell_types[badtype]); return; } if( (badtype = array_to_string(val2, &outputImage)) > 0) { set_error(tsk, "string: argument is not a string (contains non-char: %s)", cell_types[badtype]); return; } radius = pntrdouble(val3); sigma = pntrdouble(val4); amount = pntrdouble(val5); threshold = pntrdouble(val6); /* Call the method and get the return value */ result = magickUnsharpMaskImage(imageFile, outputImage, radius, sigma, amount, threshold); /* Translate the resultant pntr to be return */ pntr p_result; set_pntrdouble(p_result, result); /* set the return value */ argstack[0] = p_result; }
static void b_magickChopImage1(task *tsk, pntr *argstack) { /* pointers to the parameters */ pntr val1 = argstack[5]; // imageFile pntr val2 = argstack[4]; // outputImage pntr val3 = argstack[3]; // width pntr val4 = argstack[2]; // height pntr val5 = argstack[1]; // xPos pntr val6 = argstack[0]; // yPos int badtype; /* the result value to be return */ int result; char *imageFile; char *outputImage; int width; int height; int xPos; int yPos; /* Check validity of each parameter */ CHECK_ARG(5, CELL_CONS); CHECK_ARG(4, CELL_CONS); CHECK_ARG(3, CELL_NUMBER); CHECK_ARG(2, CELL_NUMBER); CHECK_ARG(1, CELL_NUMBER); CHECK_ARG(0, CELL_NUMBER); /* Initialize all arguments for this method */ if( (badtype = array_to_string(val1, &imageFile)) > 0) { set_error(tsk, "string: argument is not a string (contains non-char: %s)", cell_types[badtype]); return; } if( (badtype = array_to_string(val2, &outputImage)) > 0) { set_error(tsk, "string: argument is not a string (contains non-char: %s)", cell_types[badtype]); return; } width = pntrdouble(val3); height = pntrdouble(val4); xPos = pntrdouble(val5); yPos = pntrdouble(val6); /* Call the method and get the return value */ result = magickChopImage(imageFile, outputImage, width, height, xPos, yPos); /* Translate the resultant pntr to be return */ pntr p_result; set_pntrdouble(p_result, result); /* set the return value */ argstack[0] = p_result; }
static void b_magickModulateImage1(task *tsk, pntr *argstack) { /* pointers to the parameters */ pntr val1 = argstack[4]; // imageFile pntr val2 = argstack[3]; // outputImage pntr val3 = argstack[2]; // brightness pntr val4 = argstack[1]; // saturation pntr val5 = argstack[0]; // hue int badtype; /* the result value to be return */ int result; char *imageFile; char *outputImage; double brightness; double saturation; double hue; /* Check validity of each parameter */ CHECK_ARG(4, CELL_CONS); CHECK_ARG(3, CELL_CONS); CHECK_ARG(2, CELL_NUMBER); CHECK_ARG(1, CELL_NUMBER); CHECK_ARG(0, CELL_NUMBER); /* Initialize all arguments for this method */ if( (badtype = array_to_string(val1, &imageFile)) > 0) { set_error(tsk, "string: argument is not a string (contains non-char: %s)", cell_types[badtype]); return; } if( (badtype = array_to_string(val2, &outputImage)) > 0) { set_error(tsk, "string: argument is not a string (contains non-char: %s)", cell_types[badtype]); return; } brightness = pntrdouble(val3); saturation = pntrdouble(val4); hue = pntrdouble(val5); /* Call the method and get the return value */ result = magickModulateImage(imageFile, outputImage, brightness, saturation, hue); /* Translate the resultant pntr to be return */ pntr p_result; set_pntrdouble(p_result, result); /* set the return value */ argstack[0] = p_result; }
//// Check if the given file is a real directory or a Zip-archive static void b_zzip_dir_real(task *tsk, pntr *argstack) { char *fileName; int badtype; pntr p = argstack[0]; int dirtype; CHECK_ARG(0, CELL_CONS); if((badtype = array_to_string(p, &fileName)) >= 0){ set_error(tsk, "error1: argument is not a string (contains non-char: %s)", cell_types[badtype]); return; } //// the file to be ckecked exists, then we check it static const char* ext[] = { "", ".exe", ".EXE", 0 }; ZZIP_DIR* dir = zzip_opendir_ext_io (fileName, ZZIP_PREFERZIP, ext, 0); if(dir){ if(zzip_dir_real(dir)){ dirtype = 1; // printf("%s is a directory.\n", fileName); }else{ dirtype = 0; // printf("%s is a zip-archive.\n", fileName); } // zzip_dir_close(dir); }else{ //// file failed to be open dirtype = -1; } setnumber(&argstack[0], dirtype); return; }
static int serialise_arg(task *tsk, array *arr, int argno, pntr val) { char *str; char *escaped; sysobject *so; switch (pntrtype(val)) { case CELL_NUMBER: array_printf(arr," %f",pntrdouble(val)); return 1; case CELL_CONS: case CELL_AREF: if (0 <= array_to_string(val,&str)) { escaped = escape(str); array_printf(arr," \"%s\"",escaped); free(escaped); free(str); return 1; } break; case CELL_NIL: array_printf(arr," nil"); return 1; case CELL_SYSOBJECT: so = psysobject(val); if (SYSOBJECT_JAVA == so->type) { array_printf(arr," @%d",so->jid.jid); return 1; } break; } return set_error(tsk,"jcall: argument %d invalid (%s)",argno,cell_types[pntrtype(val)]); }
void dump_arraylist(GList *list) { GList *tmplist; for (tmplist=g_list_first(list);tmplist;tmplist=tmplist->next) { gchar *tmp = array_to_string((gchar **)tmplist->data); g_print("%s\n",tmp); g_free(tmp); } }
FACT_t run_file_soft (func_t *scope) { char *filename; func_t *in; in = get_func (scope, "in"); filename = array_to_string (get_var (scope, "filename")); return run_file (in, filename, false); }
int get_callinfo(task *tsk, pntr obj, pntr method, char **targetname, char **methodname) { if (0 > array_to_string(method,methodname)) return set_error(tsk,"jcall: method is not a string"); if ((CELL_SYSOBJECT == pntrtype(obj)) && (SYSOBJECT_JAVA == psysobject(obj)->type)) { char *str = malloc(100); sprintf(str,"@%d",psysobject(obj)->jid.jid); *targetname = str; } else if ((CELL_AREF == pntrtype(obj)) || (CELL_CONS == pntrtype(obj))) { if (0 > array_to_string(obj,targetname)) return set_error(tsk,"jcall: class name is not a string"); } else { return set_error(tsk,"jcall: first arg must be a java object or class name"); } return 1; }
gchar *arraylist_to_string(GList *arraylist, gchar *delimiter) { GString *strbuffer; GList *tmplist; strbuffer = g_string_sized_new(4096); for (tmplist=g_list_first(arraylist);tmplist;tmplist=g_list_next(tmplist)) { gchar *tmp = array_to_string(tmplist->data); strbuffer = g_string_append(strbuffer,tmp); g_free(tmp); strbuffer = g_string_append(strbuffer,(char *) delimiter); } return g_string_free(strbuffer, FALSE); }
FACT_t open_file (func_t *scope) { FACT_t return_value; char *filename; char *mode; FILE *return_object; filename = array_to_string (get_var (scope, "filename")); mode = array_to_string (get_var (scope, "mode")); return_object = fopen (filename, mode); if (return_object == NULL) FACT_ret_error (scope, combine_strs ("could not open file ", filename)); return_value.type = FUNCTION_TYPE; return_value.f_point = alloc_func (); return_value.f_point->name = filename; return_value.f_point->usr_data = (void *) return_object; return return_value; }
FACT_t lock_object (func_t *scope) { FACT_t return_value; var_t *obj_name; var_t *obj_var; func_t *obj_func; func_t *search; search = get_func (scope, "search"); obj_name = get_var (scope, "name"); obj_var = get_var (search, array_to_string (obj_name)); if (obj_var == NULL) { obj_func = get_func (search, array_to_string (obj_name)); if (obj_func == NULL) FACT_ret_error (scope->up, "no such object exists"); } if (obj_var != NULL) { return_value.type = VAR_TYPE; obj_var->locked = true; return_value.v_point = obj_var; lock_var_array (obj_var->array_up); } else { return_value.type = FUNCTION_TYPE; obj_func->locked = true; return_value.f_point = obj_func; lock_func_array (obj_func->array_up); } return return_value; }
//// read a file contents from either a archive of real directory void b_zzip_read(task *tsk, pntr *argstack) { char *fileName; pntr p = argstack[0]; int badtype; CHECK_ARG(0, CELL_CONS); if((badtype = array_to_string(p, &fileName)) >= 0){ set_error(tsk, "error1: argument is not a string (contains non-char: %s)", cell_types[badtype]); return; } ZZIP_FILE* fp = zzip_open (fileName, O_RDONLY|O_BINARY); if (! fp){ perror (fileName); } int bufSize = 2, blockSize = 1024, numBlocks = 1; char buf[bufSize]; int n, counter = 0; char *contents = (char *)calloc(blockSize, sizeof(char)); /* read chunks of bufSize bytes into buf and concatenate them into previous string */ while( (n = (zzip_read(fp, buf, bufSize-1))) > 0){ counter++; if(counter == 1){ // strcpy(contents, buf); strncat(contents, buf, bufSize-1); bufSize = 21; }else{ int originalSize = strlen(contents); if( ((blockSize*numBlocks) - (originalSize + 1)) < bufSize){ numBlocks++; contents = string_mkroom(contents, blockSize*numBlocks); } strncat(contents, buf, bufSize-1); // printf("%s\n\n\n", contents); } buf[n] = '\0'; } argstack[0] = string_to_array(tsk, contents); zzip_close(fp); }
/** * mdb_money_to_string * @mdb: Handle to open MDB database file * @start: Offset of the field within the current page * * Returns: the allocated string that has received the value. */ char *mdb_money_to_string(MdbHandle *mdb, int start) { #define num_bytes 8 int i; int neg=0; unsigned char multiplier[MAXPRECISION], temp[MAXPRECISION]; unsigned char product[MAXPRECISION]; unsigned char money[num_bytes]; memset(multiplier,0,MAXPRECISION); memset(product,0,MAXPRECISION); multiplier[0]=1; memcpy(money, mdb->pg_buf + start, num_bytes); /* Perform two's complement for negative numbers */ if (money[7] & 0x80) { neg = 1; for (i=0;i<num_bytes;i++) { money[i] = ~money[i]; } for (i=0; i<num_bytes; i++) { money[i] ++; if (money[i]!=0) break; } } for (i=0;i<num_bytes;i++) { /* product += multiplier * current byte */ multiply_byte(product, money[i], multiplier); /* multiplier = multiplier * 256 */ memcpy(temp, multiplier, MAXPRECISION); memset(multiplier,0,MAXPRECISION); multiply_byte(multiplier, 256, temp); } return array_to_string(product, 4, neg); }
static inline string array_to_string(const T values[N], const string& delim = UTF8_SPACE_STRING) { return array_to_string(N, values, delim); }
/* * money is a special case of numeric really...that why its here */ char * tds_money_to_string(const TDS_MONEY * money, char *s) { #ifdef HAVE_INT64 int frac; TDS_INT8 mymoney; char *p; /* sometimes money it's only 4-byte aligned so always compute 64-bit */ /* FIXME align money/double/bigint in row to 64-bit */ mymoney = (((TDS_INT8)(((TDS_INT*)money)[0])) << 32) | ((TDS_UINT*) money)[1]; p = s; if (mymoney < 0) { *p++ = '-'; mymoney = -mymoney; } mymoney = (mymoney / 50 + 1 ) / 2; frac = mymoney % 100; mymoney /= 100; /* if machine is 64 bit you do not need to split mymoney */ #if SIZEOF_LONG < 8 if (mymoney >= 1000000000) { sprintf(p, "%ld%09ld.%02d", (long)(mymoney / 1000000000), (long)(mymoney % 1000000000), frac); } else #endif sprintf(p, "%ld.%02d", (long)mymoney, frac); return s; #else unsigned char multiplier[MAXPRECISION], temp[MAXPRECISION]; unsigned char product[MAXPRECISION]; const unsigned char *number; unsigned char tmpnumber[8]; int i, num_bytes = 8; int pos, neg = 0; memset(multiplier, 0, MAXPRECISION); memset(product, 0, MAXPRECISION); multiplier[0] = 1; number = (const unsigned char *) money; #ifdef WORDS_BIGENDIAN /* big endian makes things easy */ memcpy(tmpnumber, number, 8); #else /* * money is two 32 bit ints and thus is out of order on * little endian machines. Proof of the superiority of * big endian design. ;) */ for (i = 0; i < 4; i++) tmpnumber[3 - i] = number[i]; for (i = 4; i < 8; i++) tmpnumber[7 - i + 4] = number[i]; #endif if (tmpnumber[0] & 0x80) { /* negative number -- preform two's complement */ neg = 1; for (i = 0; i < 8; i++) { tmpnumber[i] = ~tmpnumber[i]; } for (i = 7; i >= 0; i--) { tmpnumber[i] += 1; if (tmpnumber[i] != 0) break; } } for (pos = num_bytes - 1; pos >= 0; pos--) { multiply_byte(product, tmpnumber[pos], multiplier); memcpy(temp, multiplier, MAXPRECISION); memset(multiplier, 0, MAXPRECISION); multiply_byte(multiplier, 256, temp); } if (neg) { s[0] = '-'; array_to_string(product, 4, &s[1]); } else { array_to_string(product, 4, s); } /* round to two decimal places */ if (s) { sprintf(s, "%.02f", atof(s)); } return s; #endif }
//// read the directory entries of given dir/archive static void b_zzip_read_dirent(task *tsk, pntr *argstack) { char *fileName; pntr p = argstack[0]; int badtype; CHECK_ARG(0, CELL_CONS); if((badtype = array_to_string(p, &fileName)) >= 0){ set_error(tsk, "error1: argument is not a string (contains non-char: %s)", cell_types[badtype]); return; } ZZIP_DIR * dir; ZZIP_DIRENT * d; dir = zzip_opendir(fileName); if (! dir){ fprintf (stderr, "did not open %s: ", fileName); set_error(tsk, "error1: could not handle file: %s", fileName); return; } char *singleFileName; char *compressionType; int fSize = 20; char fileSize[fSize]; char compressedSize[fSize]; pntr pSingleFileName, pCompressionType, pFileSize, pCompressedSize; pntr preList, singleList; int counter = 0; /* read each dir entry, a list for each file */ while ((d = zzip_readdir (dir))){ counter++; /* orignal size / compression-type / compression-ratio / filename */ singleFileName = d->d_name; pSingleFileName = string_to_array(tsk, singleFileName); //// convert the string to cons list // sprintf(compressionType, "%s ", zzip_compr_str(d->d_compr)); //// NOTE: executing this func will change the tsk->steamstack, very weird //// NOTE: overflow caused here compressionType = (char *)zzip_compr_str(d->d_compr); pCompressionType = string_to_array(tsk, compressionType); // snprintf(fileSize, 5, "%d ", d->st_size); //// NOTE: executing this func will change the tsk->steamstack, very weird format_double(fileSize, fSize, d->st_size); pFileSize = string_to_array(tsk, fileSize); // sprintf(compressedSize, "%d ", d->d_csize); format_double(compressedSize, fSize, d->d_csize); pCompressedSize = string_to_array(tsk, compressedSize); // printf("cell type: %s \t", cell_type(preList)); //// link the cons lists to form a new list // singleList = connect_lists(tsk, &pSingleFileName, &pCompressionType); // singleList = connect_lists(tsk, &singleList, &pFileSize); // singleList = connect_lists(tsk, &singleList, &pCompressedSize); //// make cons from the last element to the beginning element singleList = make_cons(tsk, pCompressedSize, tsk->globnilpntr); singleList = make_cons(tsk, pFileSize, singleList); singleList = make_cons(tsk, pCompressionType, singleList); singleList = make_cons(tsk, pSingleFileName, singleList); if(counter == 1){ preList = make_cons(tsk, singleList, tsk->globnilpntr); // printf("cell type: %s \t", cell_type(preList)); }else{ preList = make_cons(tsk, singleList, preList); // printf("cell type: %s \n", cell_type(preList)); } } argstack[0] = preList; // printf("cell type: %s \n", cell_type(argstack[0])); }
static gint save_config_file(GList * config_list, gchar * filename) { gchar *tmpstring = NULL, *tmpstring2; GList *rclist, *tmplist, *tmplist2; Tconfig_list_item *tmpitem; DEBUG_MSG("save_config_file, started\n"); rclist = NULL; /* We must first make a list with 1 string per item. */ tmplist = g_list_first(config_list); while (tmplist != NULL) { DEBUG_MSG("save_config_file, tmpitem at %p\n", tmplist->data); tmpitem = tmplist->data; DEBUG_MSG("save_config_file, identifier=%s datatype %c\n", tmpitem->identifier,tmpitem->type); switch (tmpitem->type) { case 'i': DEBUG_MSG("save_config_file, converting \"%p\" to integer\n", tmpitem); DEBUG_MSG("save_config_file, converting \"%s %i\"\n", tmpitem->identifier, *(int *) (void *) tmpitem->pointer); tmpstring = g_strdup_printf("%s %i", tmpitem->identifier, *(int *) (void *) tmpitem->pointer); DEBUG_MSG("save_config_file, adding %s\n", tmpstring); rclist = g_list_append(rclist, tmpstring); break; case 's': DEBUG_MSG("save_config_file, converting \"%p\" to string\n", tmpitem); DEBUG_MSG("save_config_file, converting \"%s %s\"\n", tmpitem->identifier, (gchar *) * (void **) tmpitem->pointer); if (*(void **) tmpitem->pointer) { tmpstring = g_strdup_printf("%s %s", tmpitem->identifier, (gchar *) * (void **) tmpitem->pointer); DEBUG_MSG("save_config_file, adding %s\n", tmpstring); rclist = g_list_append(rclist, tmpstring); } break; case 'e': DEBUG_MSG("save_config_file, converting \"%p\"\n", tmpitem); DEBUG_MSG("save_config_file, converting \"%s %s\"\n", tmpitem->identifier, (gchar *) * (void **) tmpitem->pointer); if (*(void **) tmpitem->pointer) { tmpstring2 = escape_string((gchar*)*(void**)tmpitem->pointer, FALSE); tmpstring = g_strdup_printf("%s %s", tmpitem->identifier, tmpstring2); DEBUG_MSG("save_config_file, adding %s\n", tmpstring); rclist = g_list_append(rclist, tmpstring); g_free(tmpstring2); } break; case 'l': case 'm': { gint max = -1; /* by setting it to -1, it will never become zero if we substract 1 every round */ DEBUG_MSG("save_config_file, type %c, tmpitem(%p), &tmpitem=%p\n", tmpitem->type, tmpitem, &tmpitem); if (tmpitem->type == 'm') max = tmpitem->len; tmplist2 = g_list_last((GList *) * (void **) tmpitem->pointer); while (tmplist2 != NULL && max != 0) { tmpstring2 = (char *) tmplist2->data; DEBUG_MSG("save_config_file, tmpstring2(%p)=%s\n", tmpstring2, tmpstring2); tmpstring = g_strdup_printf("%s %s", tmpitem->identifier, tmpstring2); DEBUG_MSG("save_config_file, tmpstring(%p)=%s\n", tmpstring, tmpstring); rclist = g_list_append(rclist, tmpstring); tmplist2 = g_list_previous(tmplist2); max--; } } break; case 'a': DEBUG_MSG("save_config_file, tmpitem(%p), &tmpitem=%p\n", tmpitem, &tmpitem); tmplist2 = g_list_last((GList *) * (void **) tmpitem->pointer); DEBUG_MSG("save_config_file, the tmplist2(%p)\n", tmplist2); while (tmplist2 != NULL) { tmpstring2 = array_to_string((char **) tmplist2->data); tmpstring = g_strdup_printf("%s %s", tmpitem->identifier, tmpstring2); DEBUG_MSG("save_config_file, tmpstring(%p)=%s\n", tmpstring, tmpstring); rclist = g_list_append(rclist, tmpstring); tmplist2 = g_list_previous(tmplist2); g_free(tmpstring2); } break; default: break; } tmplist = g_list_next(tmplist); } put_stringlist(filename, rclist); free_stringlist(rclist); return 1; }
static void b_drawRectangles1(task *tsk, pntr *argstack) { /* pointers to the parameters */ pntr val1 = argstack[3]; // userName pntr val2 = argstack[2]; // xPos pntr val3 = argstack[1]; // yPos pntr val4 = argstack[0]; // rect int badtype; /* the result value to be return */ int numRect; char *userName; double xPos; int yPos; Rectangle *rect = new_Rectangle(); /* Check validity of each parameter */ CHECK_ARG(3, CELL_CONS); CHECK_ARG(2, CELL_NUMBER); CHECK_ARG(1, CELL_NUMBER); CHECK_ARG(0, CELL_CONS); /* Initialize all arguments for this method */ if( (badtype = array_to_string(val1, &userName)) > 0) { set_error(tsk, "string: argument is not a string (contains non-char: %s)", cell_types[badtype]); return; } xPos = pntrdouble(val2); yPos = pntrdouble(val3); /* Initialize the struct: Rectangle */ pntr rect_val1 = head(tsk, val4); rect->width = pntrdouble(rect_val1); pntr rect_val2 = head(tsk, tail(tsk, val4)); if( (badtype = array_to_string(rect_val2, &(rect->creator) )) > 0) { set_error(tsk, "string: argument is not a string (contains non-char: %s)", cell_types[badtype]); return; } pntr rect_val3 = head(tsk, tail(tsk, tail(tsk, val4))); rect->height = pntrdouble(rect_val3); /* Initialize another struct: Color*/ Color *rect_col = new_Color( ); rect->col = rect_col; /* new root pntr for struct Color */ pntr rect_col_val = head(tsk, tail(tsk, tail(tsk, tail(tsk, val4)))); pntr rect_col_val1 = head(tsk, rect_col_val); rect_col->red = pntrdouble(rect_col_val1); pntr rect_col_val2 = head(tsk, tail(tsk, rect_col_val)); rect_col->blue = pntrdouble(rect_col_val2); pntr rect_col_val3 = head(tsk, tail(tsk, tail(tsk, rect_col_val))); rect_col->green = pntrdouble(rect_col_val3); /* Initialize another struct: gray*/ gray *rect_col_cg = new_gray( ); rect_col->cg = rect_col_cg; /* new root pntr for struct gray */ pntr rect_col_cg_val = head(tsk, tail(tsk, tail(tsk, tail(tsk, rect_col_val)))); pntr rect_col_cg_val1 = head(tsk, rect_col_cg_val); if( (badtype = array_to_string(rect_col_cg_val1, &(rect_col_cg->country) )) > 0) { set_error(tsk, "string: argument is not a string (contains non-char: %s)", cell_types[badtype]); return; } pntr rect_col_cg_val2 = head(tsk, tail(tsk, rect_col_cg_val)); rect_col_cg->grayCode = pntrdouble(rect_col_cg_val2); /* end Initialization of struct Rectangle */ /* Call the method and get the return value */ numRect = drawRectangles(userName, xPos, yPos, rect); setnumber(&argstack[0], numRect); }
/* enlarge() */ static void b_enlargeRect1(task *tsk, pntr *argstack) { /* pointers to the parameters */ pntr val1 = argstack[1]; // originalRect pntr val2 = argstack[0]; // times int badtype; /* the result value to be return */ Rectangle *rect_return = new_Rectangle(); Rectangle *originalRect = new_Rectangle(); int times; /* Check validity of each parameter */ CHECK_ARG(1, CELL_CONS); CHECK_ARG(0, CELL_NUMBER); /* Initialize all arguments for this method */ /* Initialize the struct: Rectangle */ pntr originalRect_val1 = head(tsk, val1); originalRect->width = pntrdouble(originalRect_val1); pntr originalRect_val2 = head(tsk, tail(tsk, val1)); if( (badtype = array_to_string(originalRect_val2, &(originalRect->creator) )) > 0) { set_error(tsk, "string: argument is not a string (contains non-char: %s)", cell_types[badtype]); return; } pntr originalRect_val3 = head(tsk, tail(tsk, tail(tsk, val1))); originalRect->height = pntrdouble(originalRect_val3); /* Initialize another struct: Color*/ Color *originalRect_col = new_Color( ); originalRect->col = originalRect_col; /* new root pntr for struct Color */ pntr originalRect_col_val = head(tsk, tail(tsk, tail(tsk, tail(tsk, val1)))); pntr originalRect_col_val1 = head(tsk, originalRect_col_val); originalRect_col->red = pntrdouble(originalRect_col_val1); pntr originalRect_col_val2 = head(tsk, tail(tsk, originalRect_col_val)); originalRect_col->blue = pntrdouble(originalRect_col_val2); pntr originalRect_col_val3 = head(tsk, tail(tsk, tail(tsk, originalRect_col_val))); originalRect_col->green = pntrdouble(originalRect_col_val3); /* Initialize another struct: gray*/ gray *originalRect_col_cg = new_gray( ); originalRect_col->cg = originalRect_col_cg; /* new root pntr for struct gray */ pntr originalRect_col_cg_val = head(tsk, tail(tsk, tail(tsk, tail(tsk, originalRect_col_val)))); pntr originalRect_col_cg_val1 = head(tsk, originalRect_col_cg_val); if( (badtype = array_to_string(originalRect_col_cg_val1, &(originalRect_col_cg->country) )) > 0) { set_error(tsk, "string: argument is not a string (contains non-char: %s)", cell_types[badtype]); return; } pntr originalRect_col_cg_val2 = head(tsk, tail(tsk, originalRect_col_cg_val)); originalRect_col_cg->grayCode = pntrdouble(originalRect_col_cg_val2); /* end Initialization of struct Rectangle */ times = pntrdouble(val2); /* Call the method and get the return value */ rect_return = enlargeRect(originalRect, times); /* Translate the resultant pntr to be return */ /* Translate C struct to ELC struct */ /* pntr for struct gray*/ pntr p_rect_return_col_cg_country = string_to_array(tsk, rect_return->col->cg->country); pntr p_rect_return_col_cg_grayCode; set_pntrdouble(p_rect_return_col_cg_grayCode, rect_return->col->cg->grayCode); /* the root pntr for struct gray */ pntr p_rect_return_col_cg = make_cons(tsk, p_rect_return_col_cg_country, make_cons(tsk, p_rect_return_col_cg_grayCode, tsk->globnilpntr)); /* pntr for struct Color*/ pntr p_rect_return_col_red; set_pntrdouble(p_rect_return_col_red, rect_return->col->red); pntr p_rect_return_col_blue; set_pntrdouble(p_rect_return_col_blue, rect_return->col->blue); pntr p_rect_return_col_green; set_pntrdouble(p_rect_return_col_green, rect_return->col->green); /* the root pntr for struct Color */ pntr p_rect_return_col = make_cons(tsk, p_rect_return_col_red, make_cons(tsk, p_rect_return_col_blue, make_cons(tsk, p_rect_return_col_green, make_cons(tsk, p_rect_return_col_cg, tsk->globnilpntr)))); /* pntr for struct Rectangle*/ pntr p_rect_return_width; set_pntrdouble(p_rect_return_width, rect_return->width); pntr p_rect_return_creator = string_to_array(tsk, rect_return->creator); pntr p_rect_return_height; set_pntrdouble(p_rect_return_height, rect_return->height); /* the root pntr for struct Rectangle */ pntr p_rect_return = make_cons(tsk, p_rect_return_width, make_cons(tsk, p_rect_return_creator, make_cons(tsk, p_rect_return_height, make_cons(tsk, p_rect_return_col, tsk->globnilpntr)))); /* set the return value */ argstack[0] = p_rect_return; /* Free the return struct */ free_Rectangle(rect_return); }