/********************************************************************************* CWholePage* CVotePageBuilder::Build() Author: Mark Howitt Created: 26/08/2003 Inputs: - Outputs: - Returns: - Purpose: Creates the voting pages URL Inputs :- Action - "Add" for add responce "Create" to get the create vote page "New" to create and process a new vote "Finish" to display final page. "view" to view a given vote VoteID - The ID of the voting poll for the vote Type - The Type of object the vote belongs to ObjectID - The page ID which the vote lives on. This is used to navigate back to the page after finishing or canceling. Response - The actual Response from the vote. "0" = Against "1" = For. ShowUser - A Flag to state wether the user has requested to be hidden or shown in the supporters table. VoteName - The name of a new vote. ClosingDate - A Date of when a vote is to close. UseYesNo - A flag to see if we want a simple yes no voting system *********************************************************************************/ bool CVotePageBuilder::Build(CWholePage* pPage) { m_pPage = pPage; // Create and initialize the page if (!InitPage(m_pPage, "VOTE", true)) { TDVASSERT(false, "FailedToBuildVotePage"); return false; } // Make sure the Vote member is clean and set to the correct Context m_CurrentVote.ResetVote(/*m_InputContext*/); // Setup the XML m_pPage->AddInside("H2G2","<VOTING-PAGE></VOTING-PAGE>"); // Get the action from the url CTDVString sAction; m_InputContext.GetParamString("action",sAction); if (sAction.IsEmpty()) { TDVASSERT(false, "No Action given!"); m_pPage->SetError("NoActionGiven"); return true; } // Now check which action we are doing and call the corisponding function bool bOk = false; if (sAction.CompareText("add")) { // We are trying to add a responce to a vote bOk = AddResponce(); } else if (sAction.CompareText("finish")) { // We've voted, now display the finish page bOk = FinishPage(); } else if(sAction.CompareText("new")) { // We're trying to create the new vote bOk = CreateNewVote(); } else if(sAction.CompareText("create")) { // We're trying to setup a new vote bOk = CreateVotePage(); } else if(sAction.CompareText("view")) { // We're trying to create the new vote bOk = ViewVote(); } else if(sAction.CompareText("removeuservote")) { // We're trying to create the new vote bOk = RemoveUserVote(); } else if(sAction.CompareText("addurl")) { bOk = SubmitUrl(); } else { // Whats the action? m_pPage->SetError("InvalidAction"); } // Check for error and then Close and return the page if (!bOk) { CTDVString sXML; if (m_iObjectID > 0) { sXML << "<OBJECT TYPE='"; if (m_iType == VOTETYPE_CLUB) { sXML << "CLUB"; } else if (m_iType == VOTETYPE_NOTICE) { sXML << "NOTICE"; } else { sXML << "UNKNOWN"; } sXML << "' ID='" << m_iObjectID << "'/>"; } m_pPage->AddInside("VOTING-PAGE",sXML); } else { // Redirect CheckAndUseRedirectIfGiven(pPage); } return true; }
int cDvbSubtitleConverter::ExtractSegment(const uchar *Data, int Length, int64_t Pts) { cBitStream bs(Data, Length * 8); if (Length > 5 && bs.GetBits(8) == 0x0F) { // sync byte int segmentType = bs.GetBits(8); if (segmentType == STUFFING_SEGMENT) return -1; int pageId = bs.GetBits(16); int segmentLength = bs.GetBits(16); if (!bs.SetLength(bs.Index() + segmentLength * 8)) return -1; cDvbSubtitlePage *page = NULL; LOCK_THREAD; for (cDvbSubtitlePage *sp = pages->First(); sp; sp = pages->Next(sp)) { if (sp->PageId() == pageId) { page = sp; break; } } if (!page) { page = new cDvbSubtitlePage(pageId); pages->Add(page); dbgpages("Create SubtitlePage %d (total pages = %d)\n", pageId, pages->Count()); } if (Pts) page->SetPts(Pts); switch (segmentType) { case PAGE_COMPOSITION_SEGMENT: { dbgsegments("PAGE_COMPOSITION_SEGMENT\n"); int pageTimeout = bs.GetBits(8); int pageVersion = bs.GetBits(4); if (pageVersion == page->Version()) break; // no update page->SetVersion(pageVersion); page->SetTimeout(pageTimeout); page->SetState(bs.GetBits(2)); bs.SkipBits(2); // reserved dbgpages("Update page id %d version %d pts %"PRId64" timeout %d state %d\n", pageId, page->Version(), page->Pts(), page->Timeout(), page->State()); while (!bs.IsEOF()) { cSubtitleRegion *region = page->GetRegionById(bs.GetBits(8), true); bs.SkipBits(8); // reserved region->SetHorizontalAddress(bs.GetBits(16)); region->SetVerticalAddress(bs.GetBits(16)); } break; } case REGION_COMPOSITION_SEGMENT: { dbgsegments("REGION_COMPOSITION_SEGMENT\n"); cSubtitleRegion *region = page->GetRegionById(bs.GetBits(8)); if (!region) break; int regionVersion = bs.GetBits(4); if (regionVersion == region->Version()) break; // no update region->SetVersion(regionVersion); bool regionFillFlag = bs.GetBit(); bs.SkipBits(3); // reserved int regionWidth = bs.GetBits(16); if (regionWidth < 1) regionWidth = 1; int regionHeight = bs.GetBits(16); if (regionHeight < 1) regionHeight = 1; region->SetSize(regionWidth, regionHeight); region->SetLevel(bs.GetBits(3)); region->SetDepth(bs.GetBits(3)); bs.SkipBits(2); // reserved region->SetClutId(bs.GetBits(8)); dbgregions("Region pageId %d id %d version %d fill %d width %d height %d level %d depth %d clutId %d\n", pageId, region->RegionId(), region->Version(), regionFillFlag, regionWidth, regionHeight, region->Level(), region->Depth(), region->ClutId()); int region8bitPixelCode = bs.GetBits(8); int region4bitPixelCode = bs.GetBits(4); int region2bitPixelCode = bs.GetBits(2); bs.SkipBits(2); // reserved if (regionFillFlag) { switch (region->Bpp()) { case 2: region->FillRegion(region8bitPixelCode); break; case 4: region->FillRegion(region4bitPixelCode); break; case 8: region->FillRegion(region2bitPixelCode); break; default: dbgregions("unknown bpp %d (%s %d)\n", region->Bpp(), __FUNCTION__, __LINE__); } } while (!bs.IsEOF()) { cSubtitleObject *object = region->GetObjectById(bs.GetBits(16), true); int objectType = bs.GetBits(2); object->SetCodingMethod(objectType); object->SetProviderFlag(bs.GetBits(2)); int objectHorizontalPosition = bs.GetBits(12); bs.SkipBits(4); // reserved int objectVerticalPosition = bs.GetBits(12); object->SetPosition(objectHorizontalPosition, objectVerticalPosition); if (objectType == 0x01 || objectType == 0x02) { object->SetForegroundPixelCode(bs.GetBits(8)); object->SetBackgroundPixelCode(bs.GetBits(8)); } } break; } case CLUT_DEFINITION_SEGMENT: { dbgsegments("CLUT_DEFINITION_SEGMENT\n"); cSubtitleClut *clut = page->GetClutById(bs.GetBits(8), true); int clutVersion = bs.GetBits(4); if (clutVersion == clut->Version()) break; // no update clut->SetVersion(clutVersion); bs.SkipBits(4); // reserved dbgcluts("Clut pageId %d id %d version %d\n", pageId, clut->ClutId(), clut->Version()); while (!bs.IsEOF()) { uchar clutEntryId = bs.GetBits(8); bool entryClut2Flag = bs.GetBit(); bool entryClut4Flag = bs.GetBit(); bool entryClut8Flag = bs.GetBit(); bs.SkipBits(4); // reserved uchar yval; uchar crval; uchar cbval; uchar tval; if (bs.GetBit()) { // full_range_flag yval = bs.GetBits(8); crval = bs.GetBits(8); cbval = bs.GetBits(8); tval = bs.GetBits(8); } else { yval = bs.GetBits(6) << 2; crval = bs.GetBits(4) << 4; cbval = bs.GetBits(4) << 4; tval = bs.GetBits(2) << 6; } tColor value = 0; if (yval) { value = yuv2rgb(yval, cbval, crval); value |= ((10 - (clutEntryId ? Setup.SubtitleFgTransparency : Setup.SubtitleBgTransparency)) * (255 - tval) / 10) << 24; } dbgcluts("%2d %d %d %d %08X\n", clutEntryId, entryClut2Flag ? 2 : 0, entryClut4Flag ? 4 : 0, entryClut8Flag ? 8 : 0, value); if (entryClut2Flag) clut->SetColor(2, clutEntryId, value); if (entryClut4Flag) clut->SetColor(4, clutEntryId, value); if (entryClut8Flag) clut->SetColor(8, clutEntryId, value); } dbgcluts("\n"); break; } case OBJECT_DATA_SEGMENT: { dbgsegments("OBJECT_DATA_SEGMENT\n"); cSubtitleObject *object = page->GetObjectById(bs.GetBits(16)); if (!object) break; int objectVersion = bs.GetBits(4); if (objectVersion == object->Version()) break; // no update object->SetVersion(objectVersion); int codingMethod = bs.GetBits(2); object->SetNonModifyingColorFlag(bs.GetBit()); bs.SkipBit(); // reserved dbgobjects("Object pageId %d id %d version %d method %d modify %d\n", pageId, object->ObjectId(), object->Version(), object->CodingMethod(), object->NonModifyingColorFlag()); if (codingMethod == 0) { // coding of pixels int topFieldLength = bs.GetBits(16); int bottomFieldLength = bs.GetBits(16); object->DecodeSubBlock(bs.GetData(), topFieldLength, true); if (bottomFieldLength) object->DecodeSubBlock(bs.GetData() + topFieldLength, bottomFieldLength, false); else object->DecodeSubBlock(bs.GetData(), topFieldLength, false); bs.WordAlign(); } else if (codingMethod == 1) { // coded as a string of characters int numberOfCodes = bs.GetBits(8); object->DecodeCharacterString(bs.GetData(), numberOfCodes); } #ifdef FINISHPAGE_HACK FinishPage(page); // flush to OSD right away #endif break; } case DISPLAY_DEFINITION_SEGMENT: { dbgsegments("DISPLAY_DEFINITION_SEGMENT\n"); int version = bs.GetBits(4); if (version != ddsVersionNumber) { bool displayWindowFlag = bs.GetBit(); windowHorizontalOffset = 0; windowVerticalOffset = 0; bs.SkipBits(3); // reserved displayWidth = windowWidth = bs.GetBits(16) + 1; displayHeight = windowHeight = bs.GetBits(16) + 1; if (displayWindowFlag) { windowHorizontalOffset = bs.GetBits(16); // displayWindowHorizontalPositionMinimum windowWidth = bs.GetBits(16) - windowHorizontalOffset + 1; // displayWindowHorizontalPositionMaximum windowVerticalOffset = bs.GetBits(16); // displayWindowVerticalPositionMinimum windowHeight = bs.GetBits(16) - windowVerticalOffset + 1; // displayWindowVerticalPositionMaximum } SetOsdData(); SetupChanged(); ddsVersionNumber = version; } break; } case DISPARITY_SIGNALING_SEGMENT: { dbgsegments("DISPARITY_SIGNALING_SEGMENT\n"); bs.SkipBits(4); // dss_version_number bool disparity_shift_update_sequence_page_flag = bs.GetBit(); bs.SkipBits(3); // reserved bs.SkipBits(8); // page_default_disparity_shift if (disparity_shift_update_sequence_page_flag) { bs.SkipBits(8); // disparity_shift_update_sequence_length bs.SkipBits(24); // interval_duration[23..0] int division_period_count = bs.GetBits(8); for (int i = 0; i < division_period_count; ++i) { bs.SkipBits(8); // interval_count bs.SkipBits(8); // disparity_shift_update_integer_part } } while (!bs.IsEOF()) { bs.SkipBits(8); // region_id bool disparity_shift_update_sequence_region_flag = bs.GetBit(); bs.SkipBits(5); // reserved int number_of_subregions_minus_1 = bs.GetBits(2); for (int i = 0; i <= number_of_subregions_minus_1; ++i) { if (number_of_subregions_minus_1 > 0) { bs.SkipBits(16); // subregion_horizontal_position bs.SkipBits(16); // subregion_width } bs.SkipBits(8); // subregion_disparity_shift_integer_part bs.SkipBits(4); // subregion_disparity_shift_fractional_part bs.SkipBits(4); // reserved if (disparity_shift_update_sequence_region_flag) { bs.SkipBits(8); // disparity_shift_update_sequence_length bs.SkipBits(24); // interval_duration[23..0] int division_period_count = bs.GetBits(8); for (int i = 0; i < division_period_count; ++i) { bs.SkipBits(8); // interval_count bs.SkipBits(8); // disparity_shift_update_integer_part } } } } break; } case END_OF_DISPLAY_SET_SEGMENT: { dbgsegments("END_OF_DISPLAY_SET_SEGMENT\n"); FinishPage(page); break; } default: dbgsegments("*** unknown segment type: %02X\n", segmentType); } return bs.Length() / 8; } return -1; }
void dedtype(RING * gbl, char *name, int inlist, int binary, int stripped, int isdir) { int had_eof; int c; int count, /* ...and repeat-count */ y, /* current line-in-screen */ shift = COLS / 4, /* amount of left/right shift */ done = FALSE, shown = FALSE, infile = -1; /* # of lines processed */ OFF_T skip = 0; tabstop = 8; Shift = 0; UsePattern = FALSE; OptBinary = binary; OptStripped = stripped; if (isdir && !OptBinary) { DIR *dp; DirentT *de; char bfr[MAXPATHLEN]; # define INO_FMT "%5lu" if ((InFile = tmpfile()) == 0) { warn(gbl, "tmp-file"); return; } if ((dp = opendir(name)) != 0) { while ((de = readdir(dp)) != NULL) { (void) ded2string(gbl, bfr, (int) NAMLEN(de), de->d_name, FALSE); FPRINTF(InFile, INO_FMT, (unsigned long) de->d_ino); FPRINTF(InFile, " %s\n", bfr); } (void) closedir(dp); rewind(InFile); } else { warn(gbl, "opendir"); FCLOSE(InFile); return; } } else InFile = fopen(name, "r"); in_dedtype = TRUE; /* disable clearing of workspace via A/a cmd */ if (InFile) { int jump = 0; dlog_comment("type \"%s\" (%s %s)\n", name, OptBinary ? "binary" : "text", isdir ? "directory" : "file"); to_work(gbl, FALSE); dyn_init(&my_text, BUFSIZ); dyn_init(&my_over, BUFSIZ); max_lines = -1; MarkLine(&infile); while (!done) { if (jump) { #if defined(HAVE_WSCRL) && defined(HAVE_WSETSCRREG) /* * If we're doing single-line scrolling past * the point we've read in the file, try to * cache pointers so that the scrolling logic * will go more smoothly. */ if (jump > 0 && jump < NumP(1) && infile + NumP(1) >= max_lines) { int line = infile; (void) StartPage(&line, TRUE, &had_eof); } #endif (void) JumpBackwards(&infile, jump); jump = 0; } markC(gbl, TRUE); y = StartPage(&infile, (int) skip, &had_eof); if (skip && !was_interrupted) { if (feof(InFile)) { skip = 0; jump = NumP(1); } else { IgnorePage(infile); skip--; } continue; } if (had_eof) { int blank; infile = TopOfPage(infile, &blank); (void) JumpToLine(infile); y = StartPage(&infile, 0, &had_eof); } shown |= FinishPage(gbl, inlist, infile, y); jump = NumP(1); reset_catcher(); switch (c = dlog_char(gbl, &count, 1)) { case CTL('K'): deddump(gbl); break; case 'w': retouch(gbl, 0); break; case '\t': if (OptBinary) { beep(); } else { tabstop = (count <= 1) ? (tabstop == 8 ? 4 : 8) : count; } break; case 'q': done = TRUE; break; case KEY_HOME: case '^': jump = infile; break; case KEY_END: case '$': infile = max_lines; skip = MaxP(); break; case KEY_PPAGE: case '\b': case 'b': if (AtTop(infile)) { beep(); } else { jump += NumP(count); } break; case KEY_NPAGE: case '\n': case ' ': case 'f': jump = 0; skip = count - 1; break; case '<': case CTL('L'): LeftOrRight(-shift * count); break; case '>': case CTL('R'): LeftOrRight(shift * count); break; case KEY_LEFT: case 'h': LeftOrRight(-count); break; case KEY_DOWN: case 'j': jump = NumP(1) - count; if ((infile - jump) > max_lines) { skip = (-jump + NumP(1) - 1) / NumP(1); jump = 0; } break; case KEY_UP: case 'k': if (AtTop(infile)) { beep(); } else { jump += count; } break; case KEY_RIGHT: case 'l': LeftOrRight(count); break; /* move work-area marker */ case 'A': count = -count; jump -= count; /*FALLTHRU */ case 'a': markset(gbl, (unsigned) (mark_W + count)); break; case '/': case '?': case 'n': case 'N': FindPattern(gbl, &infile, c); break; default: beep(); } } FCLOSE(InFile); if (shown) (void) reshow(gbl, (unsigned) inlist); showMARK(gbl->Xbase); showC(gbl); } else warn(gbl, name); in_dedtype = FALSE; }