static size_t GetTableHeader ( FILE *InputFile, unsigned char *OutputData) { size_t BytesConverted; size_t TotalConverted = 0; char Buffer[BUFFER_SIZE]; int i; /* Get the full 36 byte header, requires 3 lines */ for (i = 0; i < 3; i++) { if (!fgets (Buffer, BUFFER_SIZE, InputFile)) { return (TotalConverted); } BytesConverted = ConvertLine (Buffer, OutputData); TotalConverted += BytesConverted; OutputData += 16; if (BytesConverted != 16) { return (TotalConverted); } } return (TotalConverted); }
void DataView::Draw(BRect updateRect) { if (fData == NULL || fFileSize == 0) return; // ToDo: take "updateRect" into account! char line[255]; BPoint location(kHorizontalSpace, kVerticalSpace + fAscent); for (uint32 i = 0; i < fSizeInView; i += kBlockSize) { ConvertLine(line, i, fData + i, fSizeInView - i); DrawString(line, location); location.y += fFontHeight; } DrawSelection(); }
void ShowLine(void *line,int line_len,int position) { char * image_buffer; XImage * image_line; /* I added some clipping! */ if (line_len>rounded_length) line_len=rounded_length; if (position>m_h) return; /* alloc temp image area and XImage structure */ DEBUG(printf("Showline - 2 pt %x len %d pos %d rlen %d \n", line, line_len, position, rounded_length)); image_buffer = (char *)(calloc(sizeof(char)*sizeofPixel, rounded_length)); DEBUG(printf("Showline - 3 tmpimage %x siz %x len %x \n", image_buffer, sizeof(char)*sizeofPixel, rounded_length)); image_line = XCreateImage(display,DefaultVisual(display, SCREEN), dDepth,ZPixmap,0, (char *)image_buffer,rounded_length,1,32,0); DEBUG(printf("Showline - 4.1 image_line %x \n",image_line)); /* convert the input data into the image */ ConvertLine(line, line_len, image_line); /* Put the line into the window */ XPutImage(display,window,gc,image_line,0,0,0,position,line_len,1); XFlush(display); /* Save the line into our backing store */ memcpy((m_image_buffer+(position*rounded_length*sizeofPixel)), image_buffer, line_len*sizeofPixel); /* destroy temporary image */ XDestroyImage (image_line); DEBUG(printf("Showline - 9\n")); }
static int ExtractTables ( char *InputPathname, char *Signature, unsigned int MinimumInstances) { char Buffer[BUFFER_SIZE]; FILE *InputFile; FILE *OutputFile = NULL; size_t BytesWritten; size_t TotalBytesWritten = 0; size_t BytesConverted; unsigned int State = FIND_HEADER; unsigned int FoundTable = 0; unsigned int Instances = 0; unsigned int ThisInstance; char ThisSignature[4]; int Status = 0; /* Open input in text mode, output is in binary mode */ InputFile = fopen (InputPathname, "rt"); if (!InputFile) { printf ("Could not open %s\n", InputPathname); return (-1); } if (Signature) { /* Are there enough instances of the table to continue? */ NormalizeSignature (Signature); Instances = CountTableInstances (InputPathname, Signature); if (Instances < MinimumInstances) { printf ("Table %s was not found in %s\n", Signature, InputPathname); Status = -1; goto CleanupAndExit; } if (Instances == 0) { goto CleanupAndExit; } } /* Convert all instances of the table to binary */ while (fgets (Buffer, BUFFER_SIZE, InputFile)) { switch (State) { case FIND_HEADER: /* Ignore empty lines and lines that start with a space */ if ((Buffer[0] == ' ') || (Buffer[0] == '\n')) { continue; } NormalizeSignature (Buffer); strncpy (ThisSignature, Buffer, 4); if (Signature) { /* Ignore signatures that don't match */ if (strncmp (ThisSignature, Signature, 4)) { continue; } } /* * Get the instance number for this signature. Only the * SSDT and PSDT tables can have multiple instances. */ ThisInstance = GetNextInstance (InputPathname, ThisSignature); /* Build an output filename and create/open the output file */ if (ThisInstance > 0) { sprintf (Filename, "%4.4s%u.dat", ThisSignature, ThisInstance); } else { sprintf (Filename, "%4.4s.dat", ThisSignature); } OutputFile = fopen (Filename, "w+b"); if (!OutputFile) { printf ("Could not open %s\n", Filename); Status = -1; goto CleanupAndExit; } State = EXTRACT_DATA; TotalBytesWritten = 0; FoundTable = 1; continue; case EXTRACT_DATA: /* Empty line or non-data line terminates the data */ if ((Buffer[0] == '\n') || (Buffer[0] != ' ')) { fclose (OutputFile); OutputFile = NULL; State = FIND_HEADER; printf ("Acpi table [%4.4s] - %u bytes written to %s\n", ThisSignature, (unsigned int) TotalBytesWritten, Filename); continue; } /* Convert the ascii data (one line of text) to binary */ BytesConverted = ConvertLine (Buffer, Data); /* Write the binary data */ BytesWritten = fwrite (Data, 1, BytesConverted, OutputFile); if (BytesWritten != BytesConverted) { printf ("Write error on %s\n", Filename); fclose (OutputFile); OutputFile = NULL; Status = -1; goto CleanupAndExit; } TotalBytesWritten += BytesConverted; continue; default: Status = -1; goto CleanupAndExit; } } if (!FoundTable) { printf ("Table %s was not found in %s\n", Signature, InputPathname); } CleanupAndExit: if (OutputFile) { fclose (OutputFile); if (State == EXTRACT_DATA) { /* Received an EOF while extracting data */ printf ("Acpi table [%4.4s] - %u bytes written to %s\n", ThisSignature, (unsigned int) TotalBytesWritten, Filename); } } fclose (InputFile); return (Status); }