Overview of revisions-lib.inc

Public Function Summary

Public functions are intended to be called by the code that imports this library.

Name Summary
isdigit
revcomp

Public Function Details

isdigit

Named Parameters

a

Code

function isdigit( a ) {
  if( ord( a ) >= ord( '0' ) && ord( a ) <= ord( '9' ) ) {
    return( 1 );
  }
  return( 0 );
}

function revcomp( a, b ) {

		
top

revcomp

Named Parameters

a
b

Code

function revcomp( a, b ) {

  local_var done, rc, work_a, work_b, lena, lenb;
  local_var i, subm_a, subm_b, sub_a, sub_b;

  if( ! a ) set_kb_item( name: "nvt_debug_empty/" + get_script_oid(), value:get_script_oid() + "#-#a#-#revcomp" );
  if( ! b ) set_kb_item( name: "nvt_debug_empty/" + get_script_oid(), value:get_script_oid() + "#-#b#-#revcomp" );

  if( a == b ) {
    return( 0 );
  }

  done = 0;
  work_a = a;
  work_b = b;
  rc = 0;

  while( ! done ) {

    lena = strlen( work_a );
    lenb = strlen( work_b );

    if( lena == 0 ) {
      if( lenb > 0 ) {
        rc = -1;
        break;
      }
      if( lenb == 0 ) {
        break;
      }
    }
    for( i = 0; i < lena; i++ ) {
      if( i >= lenb ) {
        done = 1;
        rc = 1;
        break;
      }
      if( isdigit( a:work_a[i] ) && isdigit( a:work_b[i] ) ) {

        subm_a = eregmatch( pattern:"([0-9]+)", string:substr( work_a, i ) );
        subm_b = eregmatch( pattern:"([0-9]+)", string:substr( work_b, i ) );
        sub_a = subm_a[1];
        sub_b = subm_b[1];
        work_a = substr( work_a, i + strlen( sub_a ) );
        work_b = substr( work_b, i + strlen( sub_b ) );

        if( int( sub_a ) > int( sub_b ) ) {
          done = 1;
          rc = 1;
          break;
        }
        if( int( sub_a ) < int( sub_b ) ) {
          done = 1;
          rc = -1;
          break;
        }
        if( int( sub_a ) == int( sub_b ) ) {
          # If we have an emptry string here, we're done.
          if( strlen( work_a ) == 0 || strlen( work_b ) == 0 ) {
            if( strlen( work_a ) == 0 ) {
              if( strlen( work_b ) == 0 ) {
                done = 1;
                break;
              } else {
                done = 1;
                rc = -1;
                break;
              }
            } else {
              done = 1;
              rc = 1;
              break;
            }
          }
          if( work_a[0] == '.' && work_b[0] != '.' ) {
            done = 1;
            rc = 1;
            break;
          }
          if( work_a[0] != '.' && work_b[0] == '.' ) {
            done = 1;
            rc = -1;
            break;
          }
          # Both must be dots. Allow the check to proceed normally.
          break;
        }
      }
      if( ord( work_a[i] ) < ord( work_b[i] ) ) {
        done = 1;
        rc = -1;
        break;
      }
      if( ord( work_a[i] ) > ord( work_b[i] ) ) {
        done = 1;
        rc = 1;
        break;
      }
      if( i == lena-1 && lenb > lena ) {
        done = 1;
        rc = -1;
        break;
      }
    }
  }
  return( rc );
}


		
top