コード例 #1
0
ファイル: tbl_chk.c プロジェクト: hsptools/hsp-wrap
static SeqIdPtr SmartGuessMakeId (CharPtr str)
{
  CharPtr id_txt;
  SeqIdPtr sip = NULL;

  if (StringHasNoText (str)) {
    return NULL;
  } else if (StringChr (str, '|') != NULL) {
    sip = MakeSeqID (str);
  } else if (IsAllDigits (str)) {
    id_txt = (CharPtr) MemNew (sizeof (Char) * (StringLen (str) + 4));
    sprintf (id_txt, "gi|%s", str);
    sip = MakeSeqID (id_txt);
    id_txt = MemFree (id_txt);
  } else if (StringChr (str, '_') != NULL) {
    id_txt = (CharPtr) MemNew (sizeof (Char) * (StringLen (str) + 5));
    sprintf (id_txt, "oth|%s", str);
    sip = MakeSeqID (id_txt);
    id_txt = MemFree (id_txt);
  } else {
    id_txt = (CharPtr) MemNew (sizeof (Char) * (StringLen (str) + 4));
    sprintf (id_txt, "gb|%s", str);
    sip = MakeSeqID (id_txt);
    id_txt = MemFree (id_txt);
  }
  return sip;
}
コード例 #2
0
// -----------------------------------------------------------------------------
// CSTSPinConverter::ConvertToBCDL
// Converts gived value to BCD (Binary Coded Desimal) format. In normal case,
// sets each upper nibble to 0. If halfBCD is used, sets each upper nibble to F.
// Returns: aConvertedPIN: Puts converted data into this pointer
// -----------------------------------------------------------------------------
void CSTSPinConverter::ConvertToBCDL(const TDesC& aPinValue,
                                     TPtr8& aConvertedPIN, TBool aHalfBCD)
{

    //verify that each character is a digit
    if (!IsAllDigits(aPinValue))
    {
        User::Leave(KErrCorrupt);
    }
    //encode the characters as BCD (see Section 2) digits: x = BCD(PIN)
    //BCD=Binary Coded Decimal
    TUint8 mask = 0x00;
    if (aHalfBCD)
    {
        //upper nibble
        mask = 0xF0;//IIII0000
    }

    TInt length = aPinValue.Length();
    for (TInt i = 0; i < length; i++)
    {
        TUint8 currentNumber = (TUint8) aPinValue[i];

        //ignore first nibble
        TUint8 firstNibleMask = 0x0F;
        TUint8 firstNibleIgnored = (TUint8)(currentNumber & firstNibleMask);

        TUint8 result = (TUint8)(firstNibleIgnored | mask);

        aConvertedPIN.Append(result);
    }
}
コード例 #3
0
// -----------------------------------------------------------------------------
// CSTSPinConverter::ConvertToASCIIL
// Just basic conversion from TDesC to TDes8 is needed
// -----------------------------------------------------------------------------
void CSTSPinConverter::ConvertToASCIIL(const TDesC& aPinValue,
                                       TPtr8& aConvertedPIN)
{

    // verify that each character is a digit in the current code-page
    if (!IsAllDigits(aPinValue))
    {
        User::Leave(KErrCorrupt);
    }
    // if needed encode the characters as ASCII (ANSI X3.4:1968)
    aConvertedPIN.Append(aPinValue);
}
コード例 #4
0
ファイル: tbl_chk.c プロジェクト: hsptools/hsp-wrap
static BioseqPtr FetchOnlyBioseqFromID (CharPtr str)
{
   BioseqPtr    bsp = NULL;
   Uint2        entityID;
   SeqEntryPtr  sep;
   SeqIdPtr     sip = NULL;
   Int4         uid;
   time_t       t1, t2;

   t1 = time (NULL);
   uid = 0;
   TrimSpacesAroundString (str);
   if (IsAllDigits (str)) {
     if (PvtStrToLong (str, &uid)) {
       sip = ValNodeNew(NULL);
       sip->choice = SEQID_GI;
       sip->data.intvalue = uid;
     } else {
      uid = 0;
     }
   } else {
     sip = SeqIdFromAccessionDotVersion (str);
     uid = AccessionToGi (str);
   }
   sep = NULL;
   if (uid > 0) {
     sep = PubSeqSynchronousQuery (uid, 3, 0); /* retcode was 0 */
     if (sep != NULL) {
       bsp = BioseqFindInSeqEntry (sip, sep);
       entityID = ObjMgrGetEntityIDForChoice (sep); 
     }
   }
   sip = SeqIdFree (sip);
   if (debug_mode) {
    t2 = time (NULL);
    if (t2 - t1 > 1) {
      printf ("Time to download %s from ID:%d\n", str, (int) (t2 - t1));
    }
   }
   return bsp;
}
コード例 #5
0
static
VOID
ParseArgs(
    IN int argc,
    IN char* argv[],
    OUT PCSTR* ppszUserName,
    OUT PDWORD pdwId,
    OUT PBOOLEAN pbShowSid
    )
{
    DWORD dwError = 0;
    int iArg = 0;
    PSTR pszArg = NULL;
    BOOLEAN bIsId = FALSE;
    PSTR pszUserName = NULL;
    DWORD dwId = 0;
    BOOLEAN bShowSid = FALSE;

    if (argc < 2)
    {
        ShowUsage();
        exit(1);
    }

    // First, get any options.
    for (iArg = 1; iArg < argc; iArg++)
    {
        pszArg = argv[iArg];

        if (!strcmp(pszArg, "--help") || !strcmp(pszArg, "-h"))
        {
            ShowUsage();
            exit(0);
        }
        else if (!strcmp(pszArg, "--uid") || !strcmp(pszArg, "-u"))
        {
            PCSTR pszUid = NULL;

            bIsId = TRUE;

            if ((iArg + 1) >= argc)
            {
                fprintf(stderr, "Missing argument for %s option.\n", pszArg);
                ShowUsage();
                exit(1);
            }

            pszUid = argv[iArg + 1];
            iArg++;

            if (!IsAllDigits(pszUid))
            {
                fprintf(stderr, "Non-numeric argument for %s option.\n", pszArg);
                ShowUsage();
                exit(1);
            }

            dwError = StringToId(pszUid, &dwId);
            if (dwError)
            {
                fprintf(stderr, "Invalid range for %s option.\n", pszArg);
                ShowUsage();
                exit(1);
            }

            // There can be no options following this one.
            iArg++;
            break;
        }
        else if (!strcmp(pszArg, "--show-sid"))
        {
            bShowSid = TRUE;
        }
        else
        {
            break;
        }
    }

    // Now get positional arguments.
    if ((argc - iArg) >= 1)
    {
        pszUserName = argv[iArg++];
        if (LW_IS_NULL_OR_EMPTY_STR(pszUserName))
        {
           fprintf(stderr, "Please specify a non-empty user name to query for.\n");
           ShowUsage();
           exit(1);
        }
    }

    // Now verify arguments.
    if (argc > iArg)
    {
        fprintf(stderr, "Too many arguments.\n");
        ShowUsage();
        exit(1);
    }

    if (bIsId && pszUserName)
    {
        fprintf(stderr, "Please specify either a uid or user name.\n");
        ShowUsage();
        exit(1);
    }

    *ppszUserName = pszUserName;
    *pdwId = dwId;
    *pbShowSid = bShowSid;
}