@@ -42,36 +42,42 @@ static SEXP package_dependencies_scan_one(SEXP this) {
4242 s = CHAR (this );
4343 i = 0 ;
4444 save = FALSE;
45- skip = FALSE;
45+ /* A package dependency spec is a comma-separated list of package
46+ names optionally followed by a comment in parentheses specifying
47+ a version requirement (see "Package Dependencies" in WRE).
48+ The package name can be 'R' or a valid package names matching
49+ "[[:alpha:]][[:alnum:].]*[[:alnum:]]".
50+ So for valid package dependency specs we can simply iteratively
51+ "save" from the first alpha until the next not-alnum-or-period
52+ (and ignore if this gave 'R'): this will also skip the field
53+ separators and optional comments.
54+ One could arrange to skip from the end of package names until the
55+ next comma, but that still would assume valid package names.
56+ */
4657 while ((c = * s ++ ) != '\0' ) {
47- if (skip ) {
48- if (c == ',' )
49- skip = FALSE;
50- } else {
51- if (save ) {
52- if (!isalnum (c ) && (c != '.' )) {
53- save = FALSE;
54- if ((q == 'R' ) && (beg [ne ] == (i - 1 )))
55- nb -- ;
56- else {
57- end [ne ] = i - 1 ;
58- ne ++ ;
59- }
58+ if (save ) {
59+ if (!isalnum (c ) && (c != '.' )) {
60+ save = FALSE;
61+ if ((q == 'R' ) && (beg [ne ] == (i - 1 )))
62+ nb -- ;
63+ else {
64+ end [ne ] = i - 1 ;
65+ ne ++ ;
6066 }
61- } else {
62- if (isalpha (c )) {
63- save = TRUE;
64- q = c ;
65- if (nb >= size ) {
66- if (size > INT_MAX / 2 )
67- error (_ ("too many items" ));
68- size *= 2 ;
69- beg = R_Realloc (beg , size , int );
70- end = R_Realloc (end , size , int );
71- }
72- beg [nb ] = i ;
73- nb ++ ;
67+ }
68+ } else {
69+ if (isalpha (c )) {
70+ save = TRUE;
71+ q = c ;
72+ if (nb >= size ) {
73+ if (size > INT_MAX / 2 )
74+ error (_ ("too many items" ));
75+ size *= 2 ;
76+ beg = R_Realloc (beg , size , int );
77+ end = R_Realloc (end , size , int );
7478 }
79+ beg [nb ] = i ;
80+ nb ++ ;
7581 }
7682 }
7783 i ++ ;
0 commit comments