R_API void r_cons_less_str(const char *str) { int lines_count; int w, h, ch, to, ui = 1, from = 0; char *p = strdup (str); int *lines = splitlines (p, &lines_count); r_cons_set_raw (R_TRUE); r_cons_show_cursor (R_FALSE); r_cons_reset (); h = 0; while (ui) { w = r_cons_get_size (&h); to = R_MIN (lines_count, from+h); if (from+3>lines_count) from = lines_count-3; printpage (p, lines, from, to); ch = r_cons_readchar (); ch = r_cons_arrow_to_hjkl (ch); switch (ch) { case ' ': from += h; break; case 'g': from = 0; break; case 'G': from = lines_count-1-h; break; case 'q': ui = 0; break; case '\r': case '\n': case 'j': from++; break; case 'J': from+=h; break; case 'k': if (from>0) from--; break; case 'K': from = (from>=h)? from-h: 0; break; } } free (lines); r_cons_set_raw (R_FALSE); r_cons_show_cursor (R_TRUE); }
void walkpages() /* process the pages in the DVI-file */ { register bool wantpage; pagecounter = 0L; while ((opcode = skipnops()) != POST) { if (opcode != BOP) /* should be at start of page now */ errorexit(nobop); else { pagecounter++; pagenr = sget4(); /* get TeX page number */ mseek(DVIfile, 36L, relative); /* skip page header */ backpointer = sget4(); /* get previous page offset */ if (pageswitchon) if (sequenceon) wantpage = inlist(pagecounter); else wantpage = inlist(pagenr); else wantpage = TRUE; if (wantpage) { initpage(); dopage(); printpage(); } else { skippage(); } } } } /* walkpages */
int main(int argc, char *argv[]) { static const unsigned primes[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251 }; struct page page; char word[256], *str; int opt, fflag = 0; unsigned i; setlocale(LC_ALL, "C"); memset(&page, 0, sizeof page); while (-1 != (opt = getopt(argc, argv, "bfzh"))) { switch (opt) { case 'b': page.flags |= BESTFIT; break; case 'f': fflag = 1; for (i = 0; i < sizeof primes / sizeof primes[0] && i < SLOTCOUNT; i++) setbit(page.index, primes[i]); break; case 'z': printf("(struct page) : %zu\n", sizeof page); printf("offsetof(data) : %zu\n", offsetof(struct page, data)); return 0; default: fprintf(stderr, "%s [-bfzh]\n" " -b Best fit\n" " -f Fragment memory\n" " -z Print data structure sizes\n" " -h Print usage\n\n" "Report bugs to <*****@*****.**>\n", argv[0]); return (opt == 'h')? 0 : EXIT_FAILURE; } /* switch() */ } while (EOF != scanf("%256s", word)) { if (!(str = sdup(&page, word))) perror("sdup"); } if (fflag) { for (i = 0; i < sizeof primes / sizeof primes[0] && i < SLOTCOUNT; i++) clrbit(page.index, primes[i]); } printpage(&page, stdout); return 0; } /* main() */
void main(int argc, char **argv) { int t; int parse; String *h; Whist *doc; rfork(RFNAMEG); t = Tpage; ARGBEGIN{ default: usage(); case 'd': wikidir = EARGF(usage()); break; case 'h': t = Thistory; break; case 'o': t = Toldpage; break; case 'D': t = Tdiff; break; case 'P': parse = 1; }ARGEND if(argc != 1) usage(); if(t == Thistory || t==Tdiff) doc = gethistory(atoi(argv[0])); else doc = getcurrent(atoi(argv[0])); if(doc == nil) sysfatal("doc: %r"); if(parse){ printpage(doc->doc->wtxt); exits(0); } if((h = tohtml(doc, doc->doc+doc->ndoc-1, t)) == nil) sysfatal("wiki2html: %r"); write(1, s_to_c(h), s_len(h)); exits(0); }
/* write ind file */ void indwrite(char *filename, struct index *ind, int pagenum) { int i,j,hpoint=0; char datama[2048],lbuff[BUFFERLEN]; FILE *fp; int conv_euc_to_euc; if (filename && kpse_out_name_ok(filename)) fp=fopen(filename,"wb"); else { fp=stdout; #ifdef WIN32 setmode(fileno(fp), _O_BINARY); #endif } conv_euc_to_euc = is_internalUPTEX() ? 1 : 0; if (conv_euc_to_euc) set_enc_string(NULL, "euc"); convert(atama,datama); if (conv_euc_to_euc) set_enc_string(NULL, "uptex"); fputs(preamble,fp); if (fpage>0) { fprintf(fp,"%s%d%s",setpage_prefix,pagenum,setpage_suffix); } for (i=line_length=0;i<lines;i++) { if (i==0) { if (!((alphabet(ind[i].dic[0][0]))||(japanese(ind[i].dic[0])))) { if (lethead_flag) { if (symbol_flag && strlen(symbol)) { fprintf(fp,"%s%s%s",lethead_prefix,symbol,lethead_suffix); } else if (lethead_flag>0) { fprintf(fp,"%s%s%s",lethead_prefix,symhead_positive,lethead_suffix); } else if (lethead_flag<0) { fprintf(fp,"%s%s%s",lethead_prefix,symhead_negative,lethead_suffix); } } SPRINTF(lbuff,"%s%s",item_0,ind[i].idx[0]); } else if (alphabet(ind[i].dic[0][0])) { if (lethead_flag>0) { fprintf(fp,"%s%c%s",lethead_prefix,ind[i].dic[0][0],lethead_suffix); } else if (lethead_flag<0) { fprintf(fp,"%s%c%s",lethead_prefix,ind[i].dic[0][0]+32,lethead_suffix); } SPRINTF(lbuff,"%s%s",item_0,ind[i].idx[0]); } else if (japanese(ind[i].dic[0])) { if (lethead_flag) { fputs(lethead_prefix,fp); for (j=hpoint;j<(strlen(datama)/2);j++) { if ((unsigned char)ind[i].dic[0][1]<(unsigned char)datama[j*2+1]) { fprint_euc_char(fp,atama[(j-1)*2],atama[(j-1)*2+1]); hpoint=j; break; } } if (j==(strlen(datama)/2)) { fprint_euc_char(fp,atama[(j-1)*2],atama[(j-1)*2+1]); } fputs(lethead_suffix,fp); } SPRINTF(lbuff,"%s%s",item_0,ind[i].idx[0]); for (hpoint=0;hpoint<(strlen(datama)/2);hpoint++) { if ((unsigned char)ind[i].dic[0][1]<(unsigned char)datama[hpoint*2+1]) { break; } } } switch (ind[i].words) { case 1: SAPPENDF(lbuff,"%s",delim_0); break; case 2: SAPPENDF(lbuff,"%s%s",item_x1,ind[i].idx[1]); SAPPENDF(lbuff,"%s",delim_1); break; case 3: SAPPENDF(lbuff,"%s%s",item_x1,ind[i].idx[1]); SAPPENDF(lbuff,"%s%s",item_x2,ind[i].idx[2]); SAPPENDF(lbuff,"%s",delim_2); break; default: break; } printpage(ind,fp,i,lbuff); } else { if (!((alphabet(ind[i].dic[0][0]))||(japanese(ind[i].dic[0])))) { if ((alphabet(ind[i-1].dic[0][0]))||(japanese(ind[i-1].dic[0]))){ fputs(group_skip,fp); if (lethead_flag && symbol_flag) { fprintf(fp,"%s%s%s",lethead_prefix,symbol,lethead_suffix); } } } else if (alphabet(ind[i].dic[0][0])) { if (ind[i].dic[0][0]!=ind[i-1].dic[0][0]) { fputs(group_skip,fp); if (lethead_flag>0) { fprintf(fp,"%s%c%s",lethead_prefix,ind[i].dic[0][0],lethead_suffix); } else if (lethead_flag<0) { fprintf(fp,"%s%c%s",lethead_prefix,ind[i].dic[0][0]+32,lethead_suffix); } } } else if (japanese(ind[i].dic[0])) { for (j=hpoint;j<(strlen(datama)/2);j++) { if ((unsigned char)(ind[i].dic[0][0]<=(unsigned char)datama[j*2])&&((unsigned char)ind[i].dic[0][1]<(unsigned char)datama[j*2+1])) { break; } } if ((j!=hpoint)||(j==0)) { hpoint=j; fputs(group_skip,fp); if (lethead_flag!=0) { fputs(lethead_prefix,fp); fprint_euc_char(fp,atama[(j-1)*2],atama[(j-1)*2+1]); fputs(lethead_suffix,fp); } } } switch (ind[i].words) { case 1: SAPPENDF(lbuff,"%s%s%s",item_0,ind[i].idx[0],delim_0); break; case 2: if (strcmp(ind[i-1].idx[0],ind[i].idx[0])!=0 || strcmp(ind[i-1].dic[0],ind[i].dic[0])!=0) { SAPPENDF(lbuff,"%s%s%s",item_0,ind[i].idx[0],item_x1); } else { if (ind[i-1].words==1) { SAPPENDF(lbuff,"%s",item_01); } else { SAPPENDF(lbuff,"%s",item_1); } } SAPPENDF(lbuff,"%s",ind[i].idx[1]); SAPPENDF(lbuff,"%s",delim_1); break; case 3: if (strcmp(ind[i-1].idx[0],ind[i].idx[0])!=0 || strcmp(ind[i-1].dic[0],ind[i].dic[0])!=0) { SAPPENDF(lbuff,"%s%s",item_0,ind[i].idx[0]); SAPPENDF(lbuff,"%s%s%s",item_x1,ind[i].idx[1],item_x2); } else if (ind[i-1].words==1) { SAPPENDF(lbuff,"%s%s%s",item_01,ind[i].idx[1],item_x2); } else if (strcmp(ind[i-1].idx[1],ind[i].idx[1])!=0 || strcmp(ind[i-1].dic[1],ind[i].dic[1])!=0) { if (ind[i-1].words==2) SAPPENDF(lbuff,"%s%s%s",item_1,ind[i].idx[1],item_12); else SAPPENDF(lbuff,"%s%s%s",item_1,ind[i].idx[1],item_x2); } else { SAPPENDF(lbuff,"%s",item_2); } SAPPENDF(lbuff,"%s%s",ind[i].idx[2],delim_2); break; default: break; } printpage(ind,fp,i,lbuff); } } fputs(postamble,fp); if (filename) fclose(fp); }
/*----------------------------------------------------------------------------*/ void paint_window(HWND hwnd) { PAINTSTRUCT ps ; HFONT hfnt0; HDC hdc; int i,k,n,y,x; //int mm,yy; char bstr[256]; RECT rw, r; SIZE sz; #define MEMDC #ifdef MEMDC HBITMAP bm0,bm; HDC fhdc ; #endif #ifdef MEMDC fhdc = BeginPaint (hwnd, &ps); hdc = CreateCompatibleDC(fhdc); bm = CreateCompatibleBitmap(fhdc,cwx+FRM,cwy+FRM); bm0 = (HBITMAP)SelectObject(hdc,bm); #else hdc = BeginPaint(hwnd,&ps); #endif //goto pe; //fillpaint(&ps.rcPaint, Cbgd, hdc); GetClientRect(hwnd, &rw); paint_back(hdc, &rw, &r); BitBltRect(hdc, hdc_back, &ps.rcPaint); hfnt0 = (HFONT)SelectObject(hdc,hfnt_n); if (0!=synhilite) { memmove (My_Colors, darkcolors ? My_Colors_d : My_Colors_l, sizeof(My_Colors)); } My_Colors[0] = (COLORREF)-1; My_Colors[1] = mStyle.MenuFrame.TextColor; My_Colors[3] = mStyle.MenuHilite.TextColor; if (mStyle.MenuHilite.parentRelative) My_Colors[2] = grey_value (My_Colors[3]) > 128 ? 0x333333 : 0xeeeeee; else My_Colors[2] = mixcolors(&mStyle.MenuHilite); if (edp) { i=ps.rcPaint.top; k=ps.rcPaint.bottom; n=ps.rcPaint.right; i=(i-zy0)/zy; k=(k-zy0+zy-1)/zy; n=(n-zx0+zx-1)/zx; if (i<0) i=0; if (k<0) k=0; if (k>i && n>0) printpage(hdc,n,i,k); BitBlt(hdc, 0, rw.bottom-FRM, rw.right, FRM, hdc_back, 0, rw.bottom-FRM, SRCCOPY); BitBlt(hdc, rw.right-FRM, 0, FRM, rw.bottom, hdc_back, rw.right-FRM, 0, SRCCOPY); } SetTextColor (hdc, mStyle.MenuTitle.TextColor ); SetBkMode (hdc, TRANSPARENT); //SelectObject (hdc, hfnt_sb); SelectObject (hdc, fnt2); format_status(bstr,1); DrawText(hdc, bstr, strlen(bstr), &r, //mStyle.MenuTitle.justify|DT_VCENTER|DT_SINGLELINE DT_LEFT|DT_VCENTER|DT_SINGLELINE ); if (edp==NULL) goto paint_end; if (infomsg[0]) { SetBkColor (hdc, My_Colors[2]); SetTextColor (hdc, My_Colors[3]); SetBkMode (hdc,OPAQUE); SelectObject (hdc, fnt1); sprintf(bstr," %s ",infomsg); n=strlen(bstr); GetTextExtentPoint32 (hdc, bstr, n, &sz); y=cwy-sz.cy; x=cwx-sz.cx; if (x<0) x = 0; TextOut(hdc, x, y, bstr, n); } { StyleItem *pSI = &MenuInfo.Scroller; get_vscr_rect(&rw); MakeGradient_s(hdc, rw, pSI, pSI->bordered ? pSI->borderWidth : 0); } #if 0 if (lmax==0 && yy>=imin(tlin-plin,pgy) && mm>(pgx<50?pgx:pgx*6/5) ) lmax=mm; #endif paint_end: SelectObject (hdc, hfnt0); #ifdef MEMDC BitBltRect(fhdc, hdc, &ps.rcPaint); //BitBlt(fhdc,0,0,cwx+FRM,cwy+FRM,hdc,0,0,SRCCOPY); SelectObject (hdc, bm0); DeleteDC(hdc); DeleteObject (bm); #endif EndPaint (hwnd, &ps) ; if (edp && 0==scroll_lock && caret==1) ShowCaret(hwnd), caret=3; }
R_API void r_cons_less_str(const char *str) { int lines_count; RRegex *rx = NULL; int w, h, ch, to, ui = 1, from = 0, i; const char *sreg; if(str == NULL || str[0] == '\0') return; char *p = strdup (str); int *lines = splitlines (p, &lines_count); RRegexMatch **ms = malloc(lines_count * sizeof(void *)); for(i = 0; i < lines_count; i++) ms[i] = calloc(NMATCHES, sizeof(RRegexMatch)); r_cons_set_raw (R_TRUE); r_cons_show_cursor (R_FALSE); r_cons_reset (); w = h = 0; while (ui) { w = r_cons_get_size (&h); to = R_MIN (lines_count, from+h); if (from+3>lines_count) from = lines_count-3; if (from<0) from = 0; printpage (p, lines, ms, from, to, w); ch = r_cons_readchar (); ch = r_cons_arrow_to_hjkl (ch); switch (ch) { case ' ': from += h; break; case 'g': from = 0; break; case 'G': from = lines_count-1-h; break; case -1: // EOF case 'q': ui = 0; break; case '\r': case '\n': case 'j': from++; break; case 'J': from+=h; break; case 'k': if (from>0) from--; break; case 'K': from = (from>=h)? from-h: 0; break; case '/': /* search */ r_cons_reset_colors(); r_line_set_prompt("/"); sreg = r_line_readline(); from = R_MIN(lines_count - 1, from); /* repeat last search if empty string is provided */ if(sreg[0]){ /* prepare for a new search */ if(rx) r_regex_free(rx); rx = r_regex_new(sreg, ""); } else { /* we got an empty string */ from = next_match(from, ms, lines_count); break; } if(!rx) break; /* find all occurences */ if(all_matches(p, rx, ms, lines, lines_count)) from = next_match(from, ms, lines_count); break; case 'n': /* next match */ /* search already performed */ if(rx) from = next_match(from, ms, lines_count); break; case 'p': /* previous match */ if(rx) from = prev_match(from, ms); break; } } for(i = 0; i < lines_count; i++) free(ms[i]); free(ms); if(rx) r_regex_free(rx); free (lines); free (p); r_cons_reset_colors(); r_cons_set_raw (R_FALSE); r_cons_show_cursor (R_TRUE); }