xaizek / pinfo (License: GPLv2 only) (since 2018-12-07)
Console-based info and manual pages reader, which adds interactive navigation to man pages.
Commit 48f9a899f37748a91bd3cfea2aa7db66deeb062a

Move vriable declaration to the beginning of blocks to accomodate non-gcc compilers
git-svn-id: svn://svn.debian.org/svn/pinfo/pinfo/trunk@313 ea4b0d59-4df7-0310-a9f9-bf8cbe41ce66
Author: bas
Author date (UTC): 2010-09-19 13:20
Committer name: bas
Committer date (UTC): 2010-09-19 13:20
Parent(s): e81baa88acc9ec660790cb26948ffaeea5988ac9
Signing key:
Tree: 0186c1affd6a6ff22a3bbb9c0327711d45fe8cec
File Lines added Lines deleted
NEWS 2 0
src/filehandling_functions.c 3 3
src/manual.c 2 2
src/utils.c 17 9
src/video.c 11 6
File NEWS changed (mode: 100644) (index 621ace8..f22bc40)
1 1 0.6.10: 0.6.10:
2 2 - Fix issue with handling of suspend/resume and character input - Fix issue with handling of suspend/resume and character input
3 3 (thanks to Scott Mcdermott for the patch) (thanks to Scott Mcdermott for the patch)
4 - Move variable declarations to the start of a block, to accomodate non-gcc
5 compilers. Thanks to Anonymous for the patches submitted to Alioth.
4 6
5 7 0.6.9 0.6.9
6 8 - New maintainer: Bas Zoetekouw <bas@debian.org> - New maintainer: Bas Zoetekouw <bas@debian.org>
File src/filehandling_functions.c changed (mode: 100644) (index 9a4c62e..100c4d0)
... ... dirpage_lookup(char **type, char ***message, long *lines,
139 139 char name[256]; char name[256];
140 140 char file[256]; char file[256];
141 141 int i; int i;
142 char *nameend, *filestart, *fileend, *dot;
142 143
143 144 id = opendirfile(0); id = opendirfile(0);
144 145 if (!id) if (!id)
 
... ... dirpage_lookup(char **type, char ***message, long *lines,
146 147
147 148 read_item(id, type, message, lines); read_item(id, type, message, lines);
148 149
149 char *nameend, *filestart, *fileend, *dot;
150
151 150 /* search for node-links in every line */ /* search for node-links in every line */
152 151 for (i = 1; i < Lines; i++) for (i = 1; i < Lines; i++)
153 152 { {
 
... ... dirpage_lookup(char **type, char ***message, long *lines,
160 159 && (strncasecmp(filename, Message[i] + 2, filenamelen) == 0) && (strncasecmp(filename, Message[i] + 2, filenamelen) == 0)
161 160 ) )
162 161 { {
162 char *tmp;
163 163
164 164 /* skip this hit if it is not a perfect match and /* skip this hit if it is not a perfect match and
165 165 * we have already found a previous partial match */ * we have already found a previous partial match */
 
... ... dirpage_lookup(char **type, char ***message, long *lines,
170 170 } }
171 171
172 172 /* find the name of the node link */ /* find the name of the node link */
173 char *tmp = name;
173 tmp = name;
174 174 strncpy(file, filestart + 1, fileend - filestart - 1); strncpy(file, filestart + 1, fileend - filestart - 1);
175 175 file[fileend - filestart - 1] = 0; file[fileend - filestart - 1] = 0;
176 176 strncpy(name, fileend + 1, dot - fileend - 1); strncpy(name, fileend + 1, dot - fileend - 1);
File src/manual.c changed (mode: 100644) (index 51866cb..aefbecc)
... ... man_initializelinks(char *tmp, int carry)
797 797 if ((!strchr(p_t1, '(')) &&(!is_in_manlinks(manlinks, p_t1))) if ((!strchr(p_t1, '(')) &&(!is_in_manlinks(manlinks, p_t1)))
798 798 { {
799 799 char tempchar; char tempchar;
800 int breakpos;
800 int breakpos, cols_before_link;
801 801 i = mylink - tmp - 1; i = mylink - tmp - 1;
802 802 if (i < 0) if (i < 0)
803 803 i++; i++;
 
... ... man_initializelinks(char *tmp, int carry)
830 830 */ */
831 831
832 832 /* calculate the number of columns in front of the link */ /* calculate the number of columns in front of the link */
833 int cols_before_link = width_of_string(tmp, i-1);
833 cols_before_link = width_of_string(tmp, i-1);
834 834
835 835 /* a small check */ /* a small check */
836 836 if (!((use_apropos) &&(manualhistorylength == 0))) if (!((use_apropos) &&(manualhistorylength == 0)))
File src/utils.c changed (mode: 100644) (index 8da99a4..610ee2d)
... ... handlewinch()
558 558 int int
559 559 check_node_name( const char * const node_name, const char * const node_header) check_node_name( const char * const node_name, const char * const node_header)
560 560 { {
561 size_t header_len;
562 char *header, *str_start, *c;
563 int res;
564
561 565 /* if either one of node_name or node_header is NULL or a zero /* if either one of node_name or node_header is NULL or a zero
562 566 * sized string, we have nothing to check, so return success */ * sized string, we have nothing to check, so return success */
563 567 if ( (node_name==NULL) || (node_header==NULL) if ( (node_name==NULL) || (node_header==NULL)
 
... ... check_node_name( const char * const node_name, const char * const node_header)
566 570 return 1; return 1;
567 571 } }
568 572
569 size_t header_len = strlen(node_header);
573 header_len = strlen(node_header);
570 574
571 575 /* copy node_header to a local string which can be mutilated */ /* copy node_header to a local string which can be mutilated */
572 576 /* don't use strdup here, as xmalloc handles all errors */ /* don't use strdup here, as xmalloc handles all errors */
573 char *header = xmalloc( header_len + 1 );
577 header = xmalloc( header_len + 1 );
574 578 strcpy(header, node_header); strcpy(header, node_header);
575 579
576 580 /* search for "Node: foobar," in node_header */ /* search for "Node: foobar," in node_header */
577 char *str_start = strstr(header, "Node: ");
581 str_start = strstr(header, "Node: ");
578 582 if (str_start==NULL) /* no match */ if (str_start==NULL) /* no match */
579 583 { {
580 584 return 0; return 0;
 
... ... check_node_name( const char * const node_name, const char * const node_header)
582 586 /* advance str_start to the start of the node name */ /* advance str_start to the start of the node name */
583 587 str_start += strlen("Node: "); str_start += strlen("Node: ");
584 588 /* and search for the next comma, tab, or newline */ /* and search for the next comma, tab, or newline */
585 char *c = str_start;
589 c = str_start;
586 590 while ( (*c!=',') && (*c!='\t') && (*c!='\n') && (*c!='\0') ) c++; while ( (*c!=',') && (*c!='\t') && (*c!='\n') && (*c!='\0') ) c++;
587 591 *c = '\0'; *c = '\0';
588 592
589 593 /* so, now str_start point to a \0-terminated string containing the /* so, now str_start point to a \0-terminated string containing the
590 594 * node name from the header. * node name from the header.
591 595 * Let's compare it with the node_name we're looking for */ * Let's compare it with the node_name we're looking for */
592 int res = strcmp(str_start, node_name);
596 res = strcmp(str_start, node_name);
593 597
594 598 /* we're done, so free alloc'ed vars */ /* we're done, so free alloc'ed vars */
595 599 xfree(header); xfree(header);
 
... ... wcswidth(const wchar_t *wstr, size_t max_len)
642 646 int int
643 647 width_of_string( const char * const mbs, const int len) width_of_string( const char * const mbs, const int len)
644 648 { {
649 int width;
650 char *str;
651 #ifdef USE_WCHAR
652 wchar_t *wstr;
653 #endif /* USE_WCHAR */
654
645 655 if (len<0) return -1; if (len<0) return -1;
646 656 if (len==0) return 0; if (len==0) return 0;
647 657
648 int width;
649
650 658 /* copy the string to a local buffer, because we only want to /* copy the string to a local buffer, because we only want to
651 659 * compare the first len bytes */ * compare the first len bytes */
652 char *str = xmalloc(len+1);
660 str = xmalloc(len+1);
653 661 memcpy(str, mbs, len); memcpy(str, mbs, len);
654 662
655 663 #ifdef USE_WCHAR #ifdef USE_WCHAR
656 664
657 665 /* allocate a widestring */ /* allocate a widestring */
658 wchar_t *wstr = xmalloc( (len+1)*sizeof(wchar_t) );
666 wstr = xmalloc( (len+1)*sizeof(wchar_t) );
659 667
660 668 mbstowcs(wstr, str, len); mbstowcs(wstr, str, len);
661 669 width = wcswidth(wstr, len); width = wcswidth(wstr, len);
File src/video.c changed (mode: 100644) (index be684b2..cfcd417)
... ... showscreen(char **message, char *type, long lines, long pos, long cursor, int co
88 88 attrset(normal); attrset(normal);
89 89 for (i = pos;(i < lines) &&(i < pos + maxy - 2); i++) for (i = pos;(i < lines) &&(i < pos + maxy - 2); i++)
90 90 { {
91 if (!message[i]) continue;
91 int tmp;
92 92
93 int tmp = strlen(message[i]) - 1;
93 if (!message[i]) continue;
94 tmp = strlen(message[i]) - 1;
94 95 message[i][tmp] = 0; message[i][tmp] = 0;
95 96 if (tmp>column) if (tmp>column)
96 97 mvaddstr(i + 1 - pos, 0, message[i]+column); mvaddstr(i + 1 - pos, 0, message[i]+column);
 
... ... info_add_highlights(int pos, int cursor, long lines, int column, char **message)
263 264 { {
264 265 regmatch_t pmatch[1]; regmatch_t pmatch[1];
265 266 long maxpos = pos +(maxy - 2); long maxpos = pos +(maxy - 2);
267 int maxregexp;
266 268 if (maxpos > lines) if (maxpos > lines)
267 269 { {
268 270 maxpos = lines; maxpos = lines;
269 271 } }
270 272
271 int maxregexp = aftersearch ? h_regexp_num + 1 : h_regexp_num;
273 maxregexp = aftersearch ? h_regexp_num + 1 : h_regexp_num;
272 274 /* /*
273 275 * if it is after search, then we have user defined regexps+ * if it is after search, then we have user defined regexps+
274 276 * a searched regexp to highlight * a searched regexp to highlight
 
... ... info_add_highlights(int pos, int cursor, long lines, int column, char **message)
285 287 /* check if this regexp is present on this line */ /* check if this regexp is present on this line */
286 288 while (!regexec(&h_regexp[j], str, 1, pmatch, 0)) while (!regexec(&h_regexp[j], str, 1, pmatch, 0))
287 289 { {
290 int x, y;
291 char tmp;
292
288 293 /* yes, found something, so highlight it */ /* yes, found something, so highlight it */
289 294 int n = pmatch[0].rm_eo - pmatch[0].rm_so; int n = pmatch[0].rm_eo - pmatch[0].rm_so;
290 295
 
... ... info_add_highlights(int pos, int cursor, long lines, int column, char **message)
292 297 str += pmatch[0].rm_so; str += pmatch[0].rm_so;
293 298
294 299 /* calculate position on screen */ /* calculate position on screen */
295 int x = calculate_len(message[i], str);
296 int y = i - pos + 1;
300 x = calculate_len(message[i], str);
301 y = i - pos + 1;
297 302
298 303 /* save the char after the end of the match, /* save the char after the end of the match,
299 304 * and replace it by \0 */ * and replace it by \0 */
300 char tmp = str[n];
305 tmp = str[n];
301 306 str[n] = 0; str[n] = 0;
302 307
303 308 /* write out the highlighted match to screen */ /* write out the highlighted match to screen */
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/pinfo

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/pinfo

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master