1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
/* Copyright (C) 2000 Damir Zucic */
/*=============================================================================
extract_serials.c
Purpose:
Extract two residue serial numbers from a string. Minus [-],
colon [:] and tilde [~] are accepted as token separators.
Input:
(1) Pointer to the first serial number.
(2) Pointer to the second serial number.
(3) Pointer to string.
Output:
(1) The first serial number set.
(2) The second serial number set.
(3) Return value.
Return value:
(1) Positive on success.
(2) Negative on failure.
========includes:============================================================*/
#include <stdio.h>
#include <string.h>
/*======extract residue ranges:==============================================*/
int ExtractSerials_ (int *serial1P, int *serial2P, char *stringP)
{
char *tokenP;
int n;
/* Take the first token: */
if ((tokenP = strtok (stringP, "-:~")) == NULL) return -1;
/* Read the first serial number: */
if (sscanf (tokenP, "%d", &n) != 1) return -2;
*serial1P = n;
/* Try to extract the second token: */
tokenP = strtok (NULL, "-:~");
/* If the second token is not present, the second */
/* serial number should be equal to the first one: */
if (tokenP == NULL)
{
*serial2P = *serial1P;
}
/* If the second token is present, read the */
/* second serial number from this token: */
else
{
if (sscanf (tokenP, "%d", &n) != 1) return -3;
*serial2P = n;
}
/* Return positive value on success: */
return 1;
}
/*===========================================================================*/
|