/* http://wvware.sourceforge.net/caolan/Polyline.html */ static GpStatus Polyline (MetafilePlayContext *context, BYTE *data) { GpStatus status; int p; /* variable number of parameters */ SHORT num = GETS(WP1); #ifdef DEBUG_WMF printf ("Polyline %d points", num); #endif SHORT x1 = GETS(WP2); SHORT y1 = GETS(WP3); int n = 4; for (p = 1; p < num; p++) { SHORT x2 = GETS(WP(n)); n++; SHORT y2 = GETS(WP(n)); n++; #ifdef DEBUG_WMF_2 printf ("\n\tdraw from %d,%d to %d,%d", x1, y1, x2, y2); #endif GpPen *pen = gdip_metafile_GetSelectedPen (context); status = GdipDrawLine (context->graphics, pen, x1, y1, x2, y2); if (status != Ok) return status; x1 = x2; y1 = y2; } return Ok; }
int64 stream_in_module(FILE *fp) { int64 count=0; MODULE *m; while (GETBT && B(MODULE) && T(BEGIN)) { char name[1024]; memset(name,0,sizeof(name)); OK; while (GETBT && B(MODULE) && !T(END)) { OK; if T(NAME) { GETD(name,sizeof(name)); m = module_load(name,0,NULL); if (m==NULL) return stream_error("module %s version is not found", name); } else if T(VERSION) { unsigned short major, minor; GETS(major); GETS(minor); if (m->major!=major || m->minor!=minor) return stream_error("module %s version %d.%02d specified does not match version %d.%02d found", name, major, minor, m->major, m->minor); } else stream_warning("ignoring token %d in module stream", t); }
/*************************************************************************** * FUNCTION: AskForBaseAddress * * PURPOSE: Prompt user to enter base address for their I/O card. * **************************************************************************/ unsigned AskForBaseAddress(unsigned int OldOne, char *TypeString) { char msg[7]; int NewOne = 0, Success = 0, Dummy; int AddrInputPosX, AddrInputPosY; CPRINTF("\nPlease enter the %sBase Address for your card (in hex)\n", TypeString); CPRINTF("or press ENTER for %X.\n>", OldOne); AddrInputPosX = WHEREX(); AddrInputPosY = WHEREY(); do { GOTOXY(AddrInputPosX, AddrInputPosY); CLREOL(); msg[0] = 5; msg[1] = 0; GETS(msg); sscanf(msg + 2, "%x", &NewOne); IOPermission(NewOne); Success = 1; Dummy = NewOne; if (msg[1] == 0) { GOTOXY(AddrInputPosX, AddrInputPosY); CPRINTF("%X", OldOne); Success = 1; Dummy = OldOne; } } while(!Success); return (Dummy); } /* end of AskForBaseAddress */
void main(int argc, char **argv) { struct sockaddr_in target; int sock; unsigned long f, i, n, num; unsigned char bt, linha[30]; struct hostent *he; if(argc!=2) {printf("Utilização: %s Servidor\n",argv[0]);exit(1);} he=gethostbyname(argv[1]); if(!he) {printf("Falhou a resolução do nome %s\n",argv[1]);exit(1);} sock=socket(AF_INET,SOCK_STREAM,0); bzero((char *)&target,sizeof(target)); target.sin_family = AF_INET; target.sin_addr=*(struct in_addr *)he->h_addr_list[0]; target.sin_port=htons(9999); if(connect(sock,(struct sockaddr *)&target, sizeof(target))==-1) {puts("A ligação falhou"); exit(1);} do { do { printf("Numero inteiro positivo a somar (zero para terminar): "); GETS(linha,30); while(sscanf(linha,"%li",&num)!=1 || num<0) { puts("Numero invalido"); GETS(linha,30); } n=num; for(i=0;i<4;i++) {bt=n%256; write(sock,&bt,1); n=n/256; } } while(num); num=0; f=1; for(i=0;i<4;i++) {read(sock,&bt,1); num=num+bt*f; f=f*256;} printf("SOMA=%lu\n",num); } while(num); close(sock); }
int rd_A (unit *ftnunit, char *p, ftnlen len) { register int i; i = GETS (p, (int)len, '\n'); if (i < 0) return (i); while (i < len) p[i++] = ' '; return (0); }
/* http://wvware.sourceforge.net/caolan/Polygon.html */ static GpStatus Polygon (MetafilePlayContext *context, BYTE *data, int len) { GpPointF *points, *pt; GpStatus status; int p; /* variable number of parameters */ SHORT num = GETS(WP1); /* len (in WORDs) = num (WORD) + num * (x WORD + y WORD) */ if (num > len + 1) return InvalidParameter; #ifdef DEBUG_WMF printf ("Polygon %d points", num); #endif points = (GpPointF*) GdipAlloc (num * sizeof (GpPointF)); if (!points) return OutOfMemory; int n = 2; for (p = 0, pt = points; p < num; p++, pt++) { pt->X = GETS(WP(n)); n++; pt->Y = GETS(WP(n)); n++; #ifdef DEBUG_WMF printf ("\n\tpoly to %g,%g", pt->X, pt->Y); #endif } status = gdip_metafile_Polygon (context, points, num); GdipFree (points); return status; }
int rd_AW (unit *ftnunit, char *p, long w, ftnlen len) { register int i, ch; while (w > len) { GET (ch); w--; } i = GETS (p, (int)w, '\n'); if (i < 0) return i; while (i < len) p[i++] = ' '; return (0); }
unsigned AskForCountAddress(void) { char msg[7]; int NewOne = 0, Success = 0, Dummy; int AddrInputPosX, AddrInputPosY; CPRINTF("Please enter the offset for Counter 0 for your card (in hex)."); CPRINTF("\n>"); AddrInputPosX = WHEREX(); AddrInputPosY = WHEREY(); do { GOTOXY(AddrInputPosX, AddrInputPosY); CLREOL(); msg[0] = 5; msg[1] = 0; GETS(msg); sscanf(msg + 2, "%x", &NewOne); Success = 1; Dummy = NewOne; } while(!Success); return (Dummy); } /* end of AskForCountAddress */
void _gif_sw_codec( kal_int32 GIF_ox, kal_int32 GIF_oy, kal_int32 resized_width, kal_int32 resized_height, kal_uint16 transparent_index, gif_sw_image_struct *cache, kal_int32 frame_counter, kal_bool transparent_enable, kal_bool isResized, GIF_COLOR_FORMAT_ENUM gif_color_format, GIF_COLOR_FORMAT_ENUM palette_format) { /*----------------------------------------------------------------*/ /* Local Variables */ /*----------------------------------------------------------------*/ kal_int32 src_clipx1, src_clipy1, src_clipx2, src_clipy2; int image_rows; int image_cols; kal_bool is_interlace; GIF_STATUS_ENUM status; /*----------------------------------------------------------------*/ /* Code Body */ /*----------------------------------------------------------------*/ //kal_uint32 start, end; //start = drv_get_current_time(); //SW_GIF_TRACE(MOD_MMI, "[gif] - _gif_sw_codec(): Enter. GIF(ox,oy)=(%d,%d), resized_width=%d, resized_height=%d\n", GIF_ox, GIF_oy, resized_width, resized_height); src_clipx1 = _get_data(FSAL_ACCESS_U16, pfsal_handle); /* X */ src_clipy1 = _get_data(FSAL_ACCESS_U16, pfsal_handle); /* Y */ image_cols = _get_data(FSAL_ACCESS_U16, pfsal_handle); /* W */ image_rows = _get_data(FSAL_ACCESS_U16, pfsal_handle); /* H */ src_clipx2 = src_clipx1 + image_cols - 1; src_clipy2 = src_clipy1 + image_rows - 1; // If need not to draw, still need to decode to get correct next frame position status = gif_sw_resizer_init( cache->image_width, cache->image_height, src_clipx1, src_clipy1, src_clipx2, src_clipy2, GIF_ox, GIF_oy, GIF_ox + resized_width - 1, GIF_oy + resized_height - 1, gif_color_format); if (status != GIF_STATUS_OK) { /* decode limitation, output width too large */ SW_GIF_TRACE(GIF_TRACE_MOD, "[gif] - _gif_sw_codec() Fail: output width too large \n"); //GIF_SW_RAISE(1); GIF_SW_RAISE(status); } cache->last_frame_x1 = (kal_int16) GIF_SW_RESIZER.want_dx1 - GIF_ox; cache->last_frame_y1 = (kal_int16) GIF_SW_RESIZER.want_dy1 - GIF_oy; cache->last_frame_x2 = (kal_int16) GIF_SW_RESIZER.want_dx2 - GIF_ox; cache->last_frame_y2 = (kal_int16) GIF_SW_RESIZER.want_dy2 - GIF_oy; { kal_int32 n; n = _get_data(FSAL_ACCESS_U8, pfsal_handle) & 0xFF; /* W05.39 Fix n value will be changed and the interlace attribute may be incorrect */ if (n & 0x40) { is_interlace = KAL_TRUE; } else { is_interlace = KAL_FALSE; } if (n & 0x80) { gif_sw_color_from_rgb_func palette_color_from_rgb; kal_int32 i; n = 1 << ((n & 0x7) + 1); g_gif_sw_current_palette = g_gif_sw_local_palette; if (gif_color_format == GIF_SW_COLOR_FORMAT_8) { #if defined(GIF_SUPPORT_SET_PALETTE_FORMAT) palette_color_from_rgb = gif_sw_color_from_rgb_array[palette_format]; #else palette_color_from_rgb = GIF_SW_PALETTE_COLOR_FROM_RGB; #endif } else { palette_color_from_rgb = g_gif_sw_act_color_from_rgb; } /* Read the local color palette */ if (n) { g_gif_sw_palette_size = n; } for (i = 0; i < n; i++) { kal_uint8 R, G, B; R = _get_data(FSAL_ACCESS_U8, pfsal_handle) & 0xFF; G = _get_data(FSAL_ACCESS_U8, pfsal_handle) & 0xFF; B = _get_data(FSAL_ACCESS_U8, pfsal_handle) & 0xFF; g_gif_sw_current_palette[i] = palette_color_from_rgb(0xFF, R, G, B); if ((g_gif_sw_dest_source_key_enable && g_gif_sw_current_palette[i] == g_gif_sw_dest_source_key) || (g_gif_sw_decoder_is_bypass_color && g_gif_sw_current_palette[i] == g_gif_sw_decoder_bypass_color)) { g_gif_sw_current_palette[i] ^= 1; } } /* current layer is index color layer */ if (gif_color_format == GIF_SW_COLOR_FORMAT_8) { for (i = 0; i < (kal_int32) n; i++) { if(g_gif_sw_layer_set_palette) { (*g_gif_sw_layer_set_palette)((kal_uint8) i, g_gif_sw_current_palette[i]); } g_gif_sw_current_palette[i] = i; } } } else /* use global palette */ { g_gif_sw_current_palette = cache->palette; } } { #define MaxStackSize 4096 #define NullCode (~0) int offset, y; register int x = 0; register unsigned char *c; register unsigned int datum; kal_uint32 consump_byte_cnt = 0; kal_uint32 read_byte_cnt = 0; kal_uint32 data_block_start_addr = 0; short *prefix; int count; unsigned char *packet, *pixel_stack, *suffix, *top_stack; unsigned int available, bits, clear, code, code_mask, code_size, data_size, first, end_of_information, in_code, old_code, pass; void (*put_pixel)(kal_int32* want_sx,gif_sw_color c,kal_bool want_draw); kal_int32 wantx = 0; kal_int32 wantx0 = 0; wantx0 = GIF_SW_RESIZER.want_start_sx;//(kal_int16)((((GIF_SW_RESIZER.want_start_dx - GIF_ox) * GIF_SW_RESIZER.src_width_range << 1) + GIF_SW_RESIZER.dest_width_range) / (GIF_SW_RESIZER.dest_width_range << 1)); put_pixel = put_pixel_with_transparent_enable; if (!transparent_enable) { put_pixel = put_pixel_with_transparent_disable; } /* allocate decoder tables */ { kal_uint8 *mem = (kal_uint8*) g_gif_sw_tree_buffer; prefix = (short*)mem; mem += MaxStackSize * sizeof(*prefix); suffix = (unsigned char*)mem; mem += MaxStackSize; pixel_stack = (unsigned char*)mem; /* use MaxStackSize+1 bytes; */ } /* Initialize GIF data stream decoder. */ data_size = _get_data(FSAL_ACCESS_U8, pfsal_handle) & 0xFF; if (data_size > 8) { SW_GIF_TRACE(GIF_TRACE_MOD, "[gif] - _gif_sw_codec() Fail: CorruptImage \n"); //GIF_SW_RAISE(1); /* CorruptImage */ GIF_SW_RAISE(GIF_STATUS_DEC_ERROR_INVALID_FILE); /* CorruptImage */ } clear = 1 << data_size; end_of_information = clear + 1; available = clear + 2; old_code = NullCode; code_size = data_size + 1; code_mask = (1 << code_size) - 1; for (code = 0; code < clear; code++) { prefix[code] = 0; suffix[code] = (unsigned char)code; } /* decode gif pixel stream */ datum = 0; bits = 0; c = 0; count = 0; first = 0; offset = 0; pass = 0; top_stack = pixel_stack; data_block_start_addr = _gif_fsal_tell(pfsal_handle); for (y = src_clipy1; y <= src_clipy2; y++) { if(g_gif_sw_image_progress_callback) { if(!(*g_gif_sw_image_progress_callback)()) { SW_GIF_TRACE(GIF_TRACE_MOD, "[gif] - _gif_sw_codec() Fail: GIF_SW_RET_DECODE_TIME_OUT. x=%d, y=%d \n", x, y); //GIF_SW_RAISE(GIF_SW_RET_DECODE_TIME_OUT); GIF_SW_RAISE(GIF_STATUS_DECODE_TIME_OUT); } } /* move to 0,offset */ wantx = wantx0; for (x = src_clipx1; x <= src_clipx2;) { kal_int32 decoded_pixel_count = 0; kal_int32 next_dst_data_distance = 0; /* ImageMagick Open Source Code Segment Start */ if (top_stack == pixel_stack) { if (bits < code_size) { /* Load bytes until there is enough bits for a code. */ if (count == 0) { /* Read a new data block. */ count = _get_data(FSAL_ACCESS_U8, pfsal_handle) & 0xFF; read_byte_cnt += count; if (count == 0) { break; } packet = (unsigned char*)g_gif_sw_stack; /* this will only use 256 bytes */ GETS(c, packet, count); } datum += ((unsigned int)(*c)) << bits; bits += 8; c++; count--; continue; } /* Get the next code. */ code = datum & code_mask; datum >>= code_size; bits -= code_size; /* Interpret the code */ if ((code > available) || (code == end_of_information)) { SW_GIF_TRACE(GIF_TRACE_MOD, "[gif] - _gif_sw_codec() Fail: Interpret the code \n"); FLUSH(count); while (!IS_EOF()) // skip he remaining data blocks of the frame. { count = _get_data(FSAL_ACCESS_U8, pfsal_handle) & 0xFF; if(count == 0) { break; } FLUSH(count); } return; } if (code == clear) { /* Reset decoder. */ code_size = data_size + 1; code_mask = (1 << code_size) - 1; available = clear + 2; old_code = NullCode; continue; } if (old_code == NullCode) { *top_stack++ = suffix[code]; old_code = code; first = code; continue; } in_code = code; if (code >= available) { *top_stack++ = (unsigned char)first; code = old_code; } while (code >= clear) { if ((top_stack - pixel_stack) >= MaxStackSize) { break; } *top_stack++ = suffix[code]; code = (unsigned int)prefix[code]; } first = (unsigned int)suffix[code]; /* Add a new string to the string table, */ if ((top_stack - pixel_stack) >= MaxStackSize) { SW_GIF_TRACE(GIF_TRACE_MOD, "[gif] - _gif_sw_codec() Fail: (top_stack - pixel_stack) >= MaxStackSize)\n"); break; } if (available >= MaxStackSize) { SW_GIF_TRACE(GIF_TRACE_MOD, "[gif] - _gif_sw_codec() Fail: available >= MaxStackSize\n"); break; } *top_stack++ = (unsigned char)first; prefix[available] = (short)old_code; suffix[available] = (unsigned char)first; available++; if (((available & code_mask) == 0) && (available < MaxStackSize)) { code_size++; code_mask += available; } old_code = in_code; } top_stack--; /* ImageMagick Open Source Code Segment End */ /* Pop a pixel off the pixel stack. */ if (isResized) { decoded_pixel_count = top_stack - pixel_stack; //how many decoded pixels if ((src_clipy1 + offset) == GIF_SW_RESIZER.want_sy) { if (wantx >= x) { next_dst_data_distance = wantx - x;// how long the distance including x } else { next_dst_data_distance = src_clipx2 - x; } if (decoded_pixel_count < next_dst_data_distance) { //it means all the decoded data this time shall be discarded. x += decoded_pixel_count; top_stack -= (decoded_pixel_count); } else { //some pixels in the decoded pixels shall be output to the dst image. x += next_dst_data_distance;//GIF_SW_RESIZER.want_sx; top_stack -= (next_dst_data_distance); } } else { //The source lineY shall be discarded for the resized image. //wantx shall be GIF_SW_RESIZER.want_sx_table for all x (no need to update wantx) if ((x + decoded_pixel_count) > src_clipx2) { next_dst_data_distance = src_clipx2 - x; } else { next_dst_data_distance = decoded_pixel_count; } x += next_dst_data_distance;//GIF_SW_RESIZER.want_sx; top_stack -= (next_dst_data_distance); } } if ((x == wantx) && ((src_clipy1 + offset) == GIF_SW_RESIZER.want_sy)) { kal_uint32 index = (kal_uint32) *top_stack; put_pixel(&wantx, ((gif_sw_color) g_gif_sw_current_palette[index]), ((kal_bool) (transparent_index != index))); } x++; } /* x loop */ gif_sw_resizer_update_wanty(&wantx, is_interlace); if (!is_interlace) { offset++; } else { switch (pass) { case 0: default: { offset += 8; if (offset >= image_rows) { pass++; offset = 4; } break; } case 1: { offset += 8; if (offset >= image_rows) { pass++; offset = 2; } break; } case 2: { offset += 4; if (offset >= image_rows) { pass++; offset = 1; } break; } case 3: { offset += 2; break; } } gif_sw_resizer_update_interlaced_want_sy(isResized, &wantx, src_clipy1 + offset); } if (x <= src_clipx2) { //SW_GIF_TRACE(MOD_MMI, "[gif] - _gif_sw_codec() Fail: x:%d <= src_clipx2:%d \n", x, src_clipx2); break; } } /* y loop */ if (y <= src_clipy2) { //SW_GIF_TRACE(MOD_MMI, "[gif] - _gif_sw_codec() Fail:y:%d <= src_clipy2:%d \n", y, src_clipy2); //GIF_SW_RAISE(1); GIF_SW_RAISE(GIF_STATUS_DEC_ERROR_PARSE); } //if (1) { kal_uint8 val; kal_int32 remaining_cnt; kal_uint32 len, curpos; curpos = _gif_fsal_tell(pfsal_handle); remaining_cnt = (data_block_start_addr + read_byte_cnt) - curpos; if (remaining_cnt > 0) { //kal_uint32 dbg_idx = 0; //for (dbg_idx = 0; dbg_idx < (remaining_cnt); dbg_idx++) //{ // val = _get_data(FSAL_ACCESS_U8, pfsal_handle) & 0xFF; // printf("Flush The Remaining %dth Byte = %d.\n", dbg_idx, val); //} FLUSH(remaining_cnt); //SW_GIF_TRACE(MOD_MMI, "[gif] - _gif_sw_codec(): Flush1 %d bytes.\n", remaining_cnt); } } //if (1) { kal_uint32 len, curpos; kal_uint8 val; len = 0; //Flush the remaining data. while (1) // skip data blocks { count = _get_data(FSAL_ACCESS_U8, pfsal_handle) & 0xFF; curpos = _gif_fsal_tell(pfsal_handle); len += count; if (count == 0) //Block Terminator { //printf("Count = 0, Flush %d data.\n", len); break; } FLUSH(count); //SW_GIF_TRACE(MOD_MMI, "[gif] - _gif_sw_codec(): Flush2 %d bytes.\n", count); //if (count > 0) //{ // kal_uint32 dbg_idx = 0; // for (dbg_idx = 0; dbg_idx < len; dbg_idx++) // { // val = _get_data(FSAL_ACCESS_U8, pfsal_handle) & 0xFF; // printf("Flush %dth byte = %d.\n", curpos+dbg_idx, val); // } //} } } } /* codec block */ //end = drv_get_current_time(); //SW_GIF_TRACE(MOD_MMI, "[gif] - _gif_sw_codec() End. %d ticks \n", drv_get_duration_tick(start, end)); //SW_GIF_TRACE(MOD_MMI, "[gif] - _gif_sw_codec(): Leave. FileCurPos = %d\n", _gif_fsal_tell(pfsal_handle)); }
int main(int argc, char *argv[]) { int quit = 0, n, offset = 10; int ctl, mes, ret; char buf[1024]; if (argc < 2) return 0; mkfifo(CTL, 0777); mkfifo(MES, 0777); ctl = open(CTL, O_RDWR); if (ctl == -1) goto ERR1; mes = open(MES, O_RDWR); if (mes == -1) goto ERR1; if (fork() == 0) { close(2); dup2(mes, 1); execlp("mplayer", "mplayer", argv[1], "-quiet", "-slave", "-input", "file="CTL, NULL); perror("execlp"); exit(0); } sleep(1); n = fcntl(mes, F_GETFL); fcntl(mes, F_SETFL, n | O_NONBLOCK); while (read(mes, buf, sizeof(buf)) > 0) continue; fcntl(mes, F_SETFL, n); while (!quit) { START: printf("1. pause/play!\n"); printf("2. seek\n"); printf("3. get_time_pos!\n"); printf("4. get_time_length!\n"); printf("5. exit!\n"); GETS("please input [ 1 - 5 ] : ", goto START, "%d", &n); switch (n) { case 1: write(ctl, "p\n", 2); break; case 2: GETS("\tplease input seek [10] :", offset = 10, "%d", &offset); snprintf(buf, sizeof(buf), "seek %d\n", offset); write(ctl, buf, strlen(buf)); break; case 3: write(ctl, "get_time_pos\n", 13); ret = read(mes, buf, sizeof(buf)); buf[ret] = '\0'; printf("pos = %s\n", buf); break; case 4: write(ctl, "get_time_length\n", 16); ret = read(mes, buf, sizeof(buf)); buf[ret] = '\0'; printf("length = %s\n", buf); break; case 5: write(ctl, "quit\n", 5); quit = 1; break; default: break; } } ERR1: close(ctl); close(mes); unlink(CTL); unlink(MES); return 0; }
GpStatus gdip_metafile_play_wmf (MetafilePlayContext *context) { GpStatus status = Ok; GpMetafile *metafile = context->metafile; BYTE *data = metafile->data; BYTE *end = data + metafile->length; #ifdef DEBUG_WMF int i = 1, j; #endif /* reality check - each record is, at minimum, 6 bytes long (4 size + 2 function) */ while (data < end - WMF_MIN_RECORD_SIZE) { DWORD size = GETDW(RECORDSIZE); WORD func = GETW(FUNCTION); int params = size - (WMF_MIN_RECORD_SIZE / sizeof (WORD)); #ifdef DEBUG_WMF printf ("\n[#%d] size %d ", i++, size); #endif /* reality check - enough data available to read all parameters ? (params is in WORD) */ if ((params << 1) > (long)(end - data)) { status = InvalidParameter; goto cleanup; } /* Notes: * - The previous check doesn't mean we have all required parameters (only the one encoded) * - sometimes there are extra (undocumented?, buggy?) parameters for some functions */ switch (func) { case META_SAVEDC: WMF_CHECK_PARAMS(0); status = gdip_metafile_SaveDC (context); break; case META_SETBKMODE: WMF_CHECK_PARAMS(1); status = gdip_metafile_SetBkMode (context, GETW(WP1)); break; case META_SETMAPMODE: WMF_CHECK_PARAMS(1); status = gdip_metafile_SetMapMode (context, GETW(WP1)); break; case META_SETROP2: WMF_CHECK_PARAMS(1); status = gdip_metafile_SetROP2 (context, GETW(WP1)); break; case META_SETRELABS: WMF_CHECK_PARAMS(1); status = gdip_metafile_SetRelabs (context, GETW(WP1)); break; case META_SETPOLYFILLMODE: WMF_CHECK_PARAMS(1); status = gdip_metafile_SetPolyFillMode (context, GETW(WP1)); break; case META_SETSTRETCHBLTMODE: WMF_CHECK_PARAMS(1); /* 2 but second is unused (32bits?) */ status = gdip_metafile_SetStretchBltMode (context, GETW(WP1)); break; case META_RESTOREDC: WMF_CHECK_PARAMS(0); status = gdip_metafile_RestoreDC (context); break; case META_SELECTOBJECT: WMF_CHECK_PARAMS(1); status = gdip_metafile_SelectObject (context, GETW(WP1)); break; case META_SETTEXTALIGN: WMF_CHECK_PARAMS(1); status = gdip_metafile_SetTextAlign (context, GETW(WP1)); break; case META_DELETEOBJECT: WMF_CHECK_PARAMS(1); status = gdip_metafile_DeleteObject (context, GETW(WP1)); break; case META_SETBKCOLOR: WMF_CHECK_PARAMS(2); status = gdip_metafile_SetBkColor (context, GetColor (GETW(WP1), GETW(WP2))); break; case META_SETWINDOWORG: WMF_CHECK_PARAMS(2); status = gdip_metafile_SetWindowOrg (context, GETS(WP1), GETS(WP2)); break; case META_SETWINDOWEXT: WMF_CHECK_PARAMS(2); status = gdip_metafile_SetWindowExt (context, GETS(WP1), GETS(WP2)); break; case META_LINETO: WMF_CHECK_PARAMS(2); status = gdip_metafile_LineTo (context, GETS(WP1), GETS(WP2)); break; case META_MOVETO: WMF_CHECK_PARAMS(2); status = gdip_metafile_MoveTo (context, GETS(WP1), GETS(WP2)); break; case META_CREATEPENINDIRECT: /* note: documented with only 4 parameters, LOGPEN use a POINT to specify width, so y (3) is unused) */ WMF_CHECK_PARAMS(5); status = gdip_metafile_CreatePenIndirect (context, GETW(WP1), GETW(WP2), GetColor (GETW(WP4), GETW(WP5))); break; case META_CREATEBRUSHINDIRECT: WMF_CHECK_PARAMS(4); status = gdip_metafile_CreateBrushIndirect (context, GETW(WP1), GetColor (GETW(WP2), GETW(WP3)), GETW(WP4)); break; case META_POLYGON: status = Polygon (context, data, params); break; case META_POLYLINE: status = Polyline (context, data); break; case META_POLYPOLYGON: status = PolyPolygon (context, data); break; case META_ARC: WMF_CHECK_PARAMS(8); status = gdip_metafile_Arc (context, GETS(WP1), GETS(WP2), GETS(WP3), GETS(WP4), GETS(WP5), GETS(WP6), GETS(WP7), GETS(WP8)); break; case META_RECTANGLE: WMF_CHECK_PARAMS (4); status = gdip_metafile_Rectangle (context, GETS (WP1), GETS (WP2), GETS (WP3), GETS (WP4)); break; case META_SETPIXEL: WMF_CHECK_PARAMS (4); status = gdip_metafile_SetPixel (context, GetColor (GETW (WP1), GETW (WP2)), GETW (WP4), GETW (WP3)); break; case META_STRETCHDIB: { WMF_CHECK_PARAMS(14); BITMAPINFO *bmi = (BITMAPINFO*) (data + 14 * sizeof (WORD)); void* bits = (void*) (bmi + GETDW(WP12)); status = gdip_metafile_StretchDIBits (context, GETS(WP11), GETS(WP10), GETS(WP9), GETS(WP8), GETS(WP7), GETS(WP6), GETS(WP5), GETS(WP4), bits, bmi, GETW(WP3), GETDW(WP1)); break; } case META_DIBSTRETCHBLT: { WMF_CHECK_PARAMS(12); BITMAPINFO *bmi = (BITMAPINFO*) (data + 13 * sizeof (WORD)); void* bits = (void*) (bmi + GETDW(WP11)); status = gdip_metafile_StretchDIBits (context, GETS(WP10), GETS(WP9), GETS(WP8), GETS(WP7), GETS(WP6), GETS(WP5), GETS(WP4), GETS(WP3), bits, bmi, 0, GETDW(WP1)); break; } default: /* unprocessed records, ignore the data */ /* 3 for size (DWORD) == 2 * SHORT + function == 1 SHORT */ #ifdef DEBUG_WMF printf ("Unimplemented_%X (", func); for (j = 0; j < params; j++) { printf (" %d", GetParam (j, data)); } printf (" )"); #endif break; } if (status != Ok) { g_warning ("Parsing interupted, status %d returned from function %d.", status, func); goto cleanup; } data += size * 2; } cleanup: return status; }
int rd_F (unit *ftnunit, ufloat *p, long w, long d, ftnlen len) { char s[MAX_INPUT_SIZE], *sp, *c, *exppos=NULL; int ch, nfrac, exp, dot, se; int extrachars=0; int i, ich; char cc; dot = 1; /* no dot */ if (w == 0) { if (len < 8) { w = 15; d = 7; } else if (len == 8) { w = 25; d = 16; } else { w = 40; d = 32; } } if ((int) w >= MAX_INPUT_SIZE) { ch = GETS (sp = s, MAX_INPUT_SIZE-1, ','); for (i = MAX_INPUT_SIZE-1; i < w; i++) { ich = GETS (&cc, 1, ','); if (!ch) break; if (!isspace(cc)) return (errno = 186); } } else ch = GETS (sp = s, (int) w, ','); if (ch < 0) return (ch); sp[ch] = '\0'; while (*sp == ' ') sp++; if (*sp == '-') { sp++; } else { if (*sp == '+') sp++; } loop1: while (*sp >= '0' && *sp <= '9') { sp++; } if (*sp == ' ') { if (ftnunit->f77cblank) { *sp++='0'; } else {c=sp; while (*c) { *c=*(c+1); c++; } } goto loop1; } nfrac = 0; if (*sp == '.') { {c=sp; while (*c) { *c=*(c+1); c++; } } dot = 0; loop2: while (*sp >= '0' && *sp <= '9') { nfrac--; sp++; } if (*sp == ' ') { if (ftnunit->f77cblank) { *sp++='0'; nfrac--; } else {c=sp; while (*c) { *c=*(c+1); c++; } } goto loop2; } } if (*sp == 'd' || *sp == 'e' || *sp == 'D' || *sp == 'E' || *sp == 'q' || *sp == 'Q') { { exppos=sp; *sp++='e'; } } else if (*sp != '+' && *sp != '-') { nfrac -= ftnunit->f77scale; exppos=sp; } while (*sp == ' ') {c=sp; while (*c) { *c=*(c+1); c++; } } if (*sp == '-') { if (exppos==NULL) exppos=sp; sp++; se = 1; } else { if (exppos==NULL) exppos=sp; se = 0; if (*sp == '+') sp++; } exp = 0; loop3: while (*sp >= '0' && *sp <= '9') { exp = exp * 10 + (*sp - '0'); sp++; } if (*sp == ' ') { if (ftnunit->f77cblank) exp *= 10; sp++; goto loop3; } /* here we figure out if there is any unexpected characters */ if (*sp) extrachars=1; if (se) exp = nfrac - exp; else exp += nfrac; if (dot) exp -= d; *exppos++='e'; /* re-write exponent */ if (exp < 0) { *exppos++='-'; exp = - exp; } if (exp > 999) exp=999; /* currently cant handle exponents that large */ if (exp > 99) { *exppos++ = (char) ((exp/100) + '0'); exp = exp % 100; if (exp < 10) *exppos++ = '0'; } if (exp > 9) { *exppos++ = (char) ((exp/10) + '0'); exp = exp % 10; } *exppos++ = (char) (exp + '0'); *exppos = '\0'; /* now convert */ if (len < sizeof (double)) p->pf = atof(s); else if (len == sizeof (double)) p->pd = atof(s); else p->pld = atold(s); if (extrachars) return (errno = 115); else return (0); }
int rd_I (unit *ftnunit, uinteger *n, long w, ftnlen len) { register ftnll x = 0; int sign, ch; char s[MAX_INPUT_SIZE]; register char *ps, c; int i, ich; char cc; if (w == 0) w = len < 4 ? 7 : len < 8 ? 12 : 21; if ((int) w >= MAX_INPUT_SIZE) { ch = GETS (s, MAX_INPUT_SIZE-1, ','); for (i = MAX_INPUT_SIZE-1; i < w; i++) { ich = GETS (&cc, 1, ','); if (!ch) break; if (!isspace(cc)) return (errno = 186); } } else ch = GETS (s, (int) w, ','); if (ch < 0) return (ch); ps = s; ps[ch] = '\0'; while (*ps == ' ') ps++; if (*ps == '-') { sign = 1; ps++; } else { sign = 0; if (*ps == '+') ps++; } for (c = (*ps);; c = (*++ps)) { if (c >= '0' && c <= '9') x = x * 10 + c - '0'; else if (c == ' ') { /* change x *= 10 to this because there is some problem with cfe. * ---ravi--- */ if (ftnunit->f77cblank) x = x * 10; } else { if (ftnunit->f77cblank && c == '\0' && ch < w) while (ch++ < w) x = x *10; break; } } if (sign) x = -x; if (len == sizeof (short)) n->is = (short) x; else if (len == sizeof (char)) n->ic = (signed char) x; else if (len == sizeof (ftnll)) n->ill = x; else n->ii = (int) x; if (*ps) return (errno = 115); return (0); }
int main( int argc, char ** argv ) { char path[_MAX_PATH]; char buffer[ MAX_COMMAND_LINE + 2 ] = { (char)MAX_COMMAND_LINE }; /* Used with _cgets() - maximum number of characters in must be set in 1st byte */ int _argc; char * _argv[ MAX_ARGS ], * result, * fullpath; int archive_handle = -1; /* last attached archive */ int i, cmd; if( !ResInit( NULL )) return( 1 ); /* ResInit failed */ /* these would be called after parsing an .ini file or similar */ IF_DEBUG( ResDbgLogOpen( "resource.log" )); print_heading(); _getcwd( path, _MAX_PATH ); printf( "PATH: %s\n", path ); do { do { #if( !RES_USE_FLAT_MODEL ) printf( "\n%s> ", GLOBAL_CURRENT_PATH ); #else printf( "\nRoot > " ); #endif _getcwd( path, _MAX_PATH ); printf( "[SD: %s]>", path ); result = GETS( buffer ); /* Input a line of text */ } while( !buffer[1] ); if( !stricmp( result, "exit" )) break; _argc = parse_args( result, _argv ); cmd = COMMAND_ERROR; for( i=0; i<COMMAND_COUNT; i++ ) { if( !stricmp( result, command[i] )) { cmd = i; break; } } if( cmd == COMMAND_EXIT && !_argc ) break; if( _argc > 1 ) { if( !stricmp( _argv[1], "?" ) || !stricmp( _argv[1], "help" )) { show_help( cmd ); continue; } else if( strchr( _argv[1], ASCII_BACKSLASH )) { res_fullpath( path, _argv[1], _MAX_PATH ); fullpath = path; } else fullpath = _argv[1]; } switch( cmd ) { case COMMAND_DIR: #if( RES_USE_FLAT_MODEL ) printf( "This function is only meaningful when using the hierarchical model.\n" ); break; #endif if( _argc > 1 ) cmd_dir( _argv[1] ); else cmd_dir( NULL ); break; case COMMAND_ANALYZE: { #if( !RES_USE_FLAT_MODEL ) HASH_ENTRY * entry; if( _argc == 1 ) entry = hash_find( GLOBAL_CURRENT_PATH, GLOBAL_HASH_TABLE ); else entry = hash_find( fullpath, GLOBAL_HASH_TABLE ); if( entry ) { #if( RES_DEBUG_VERSION ) if( entry -> dir ) dbg_analyze_hash( (HASH_TABLE *)entry -> dir ); else printf( "No directory table for this directory.\n" ); #endif /* RES_DEBUG_VERSION */ } else printf( "Directory not found.\n" ); #else printf( "This command only meaningful when using the hierarchical model!\n" ); #endif break; } case COMMAND_RUN: cmd_run( _argc, _argv ); break; case COMMAND_CD: if( _argc > 1 ) { if( !ResSetDirectory( fullpath )) printf( "Error changing to directory %s\n", fullpath ); } else printf( "Current directory is: %s\n", GLOBAL_CURRENT_PATH ); break; case COMMAND_ADD: if( _argc > 1 ) { int test = FALSE, flag = -1; if( _argc > 2 ) flag = is_bool( _argv[2] ); if( flag == -1 ) flag = TRUE; if( !GLOBAL_SEARCH_INDEX ) test = ResCreatePath( fullpath, flag ); else test = ResAddPath( fullpath, flag ); if( !test ) printf( "Error adding %s to search path\n", fullpath ); } else show_help(cmd); break; case COMMAND_STREAM: { FILE * fptr; char c; int test; if( _argc < 2 ) { show_help(cmd); break; } fptr = fopen( _argv[1], "r" ); if( fptr ) { while( (test = fscanf( fptr, "%c", &c )) != EOF ) printf( "%c", c ); printf( "\n\n\n\n ************** REWINDING ****************** \n\n\n\n\n\n\n" ); fseek( fptr, 0, SEEK_SET ); while( (test = fscanf( fptr, "%c", &c )) != EOF ) printf( "%c", c ); fclose( fptr ); } else { printf( "Error opening file %s\n", _argv[1] ); } break; } case COMMAND_PATH: { int x=0; char b[_MAX_PATH]; if( GLOBAL_PATH_LIST ) { while( ResGetPath( x++, b )) printf( "%s\n", b ); } else printf( "No path created.\n" ); break; } case COMMAND_EXTRACT: { /* extracts the archive to the local directory with the same filename */ if( _argc < 3 ) show_help(cmd); else ResExtractFile( _argv[1], _argv[2] ); break; } case COMMAND_READ: if( _argc >= 2 ) cmd_read( _argv[1] ); else show_help(cmd); break; case COMMAND_ATTACH: { char dst[_MAX_PATH]; int flag = -1; if( _argc < 2 ) { show_help(cmd); break; } if( _argc >= 3 ) flag = is_bool( _argv[ _argc - 1 ] ); if( _argc >= 3 ) res_fullpath( dst, _argv[2], _MAX_PATH ); if( _argc == 2 ) archive_handle = ResAttach( GLOBAL_CURRENT_PATH, fullpath, FALSE ); else if( _argc == 3 ) { if( flag != -1 ) archive_handle = ResAttach( GLOBAL_CURRENT_PATH, fullpath, flag ); else archive_handle = ResAttach( fullpath, dst, FALSE ); } else if( _argc == 4 ) archive_handle = ResAttach( fullpath, dst, flag == -1 ? 0 : flag ); if( archive_handle == -1 ) printf( "Error attaching zip file %s\n", fullpath ); break; } case COMMAND_DUMP: ResDbgDump(); MemDump(); printf("\n"); MemFindLevels(); printf("\n"); MemFindUsage(); break; case COMMAND_DETACH: if( archive_handle != -1 ) { ResDetach( archive_handle ); archive_handle = -1; } else printf( "No archives currently attached.\n" ); break; case COMMAND_MAP: if( _argc < 2 ) show_help(cmd); else cmd_map( _argv[1] ); break; case COMMAND_FIND: if( _argc < 2 ) show_help(cmd); else cmd_find( fullpath ); break; case COMMAND_HELP: print_heading(); show_help(cmd); break; case COMMAND_ERROR: default: printf( "Syntax error\n" ); break; } } while( TRUE ); ResExit(); MemDump(); _getcwd( path, _MAX_PATH ); printf( "PATH: %s\n", path ); return(0); }