Category : C Source Code
Archive   : IMDSRC78.ZIP
Filename : KEYWUTIL.C

 
Output of file : KEYWUTIL.C contained in archive : IMDSRC78.ZIP
/*** IMDISP module KEYWUTIL.C

KEYWUTIL contains routines for processing PDS and FITS keywords.
Extracted from LABUTIL.C by A. Warnock, 1/91

***/

#define __MSC

/* * * * INCLUDE files * * * */

#include
#include
#include "imdef.h"
#include "imdisp.h"
#include "imdutil.h"
#include "dispio.h"
#include "fileio.h"
#include "textutil.h"

/* * * * External functions * * * */

/* * * * Function declarations * * * */

int ExtractKeywordString (char *, char *, int *, char *);
int GetKeywordInteger (char *,char *,int ,int *,int *);
int GetKeywordLong (char *, char *, long, long *, int *);
int GetKeywordReal (char *, char *, float, float *, int *);
int GetKeywordString (char *, char *, char *, char *, int *);
int GetKeywordSubcommand (char *, char *, int *);

/* * * * Global Variables * * * */

float xstart, xinterval;
char xunit[30];


int ExtractKeywordString (char * CommandString, char * Keyword, int * p_flag,
char * value)

/* ExtractKeywordString extracts the string following the keyword from
the CommandString.
flag=-1 if there is no keyword match.
flag= 0 if keyword with no value.
flag= 1 if keyword and value string.

*/

{
int i, j, k, l;
char *searchptr;


/* Find where the keyword is in the buffer */
searchptr = strstr (CommandString, Keyword);
j = searchptr - CommandString;

if ( (searchptr == NULL) || ((j > 0) && (CommandString[j-1] > ' ')) )
*p_flag = -1;
else
{
*p_flag = 1;
l = strlen(CommandString) - 1;
do /* scan past the keyword */
j++;
while ( (CommandString[j] != ' ') &&
(CommandString[j] != '=') && (j != l) );

if (j == l) *p_flag = 0;

do /* scan to the next non blank and non equal char */
j++;
while ( ( (CommandString[j] <= ' ') ||
(CommandString[j] == '=') ) && (j < l) );


k = j;
if (CommandString[j] == '"')
{
j++; /* if value begins with a quote, read to next quote */
do
k++;
while ( (CommandString[k] != '"') && (k <= l) );
}
else
{
do /* scan past the value to next space */
k++;
while ( (CommandString[k] > ' ') && (k <= l) );
}

strncpy (value, CommandString+j, k-j);
value[k-j] = 0;
}

}

int GetKeywordInteger (char * CommandString, char * Keyword, int defaul,
int * p_value, int * p_flag)

/*** GetKeywordInteger scans the CommandString for the Keyword and
returns the value of the following integer.

Parameter Type In/out Description
CommandString char ptr in The command string to scan thru
Keyword char ptr in The keyword string to match
defaul int in The default value to return if
no keyword or illegal value
p_value int ptr out The returned value
p_flag int ptr out The flag: -1 for no keyword match
0 for keyword with no/bad value
1 for keyword and good value

***/

{
char stringvalue[80];

ExtractKeywordString (CommandString, Keyword, p_flag, stringvalue);
if (*p_flag == 1)
{
if (sscanf (stringvalue, "%d", p_value) == 0)
{
*p_flag = 0;
*p_value = defaul;
}
}
else
{
*p_value = defaul;
}
}

int GetKeywordLong (char * CommandString, char * Keyword, long defaul,
long * p_value, int * p_flag)

/*** GetKeywordInteger scans the CommandString for the Keyword and
returns the value of the following integer.

Parameter Type In/out Description
CommandString char ptr in The command string to scan thru
Keyword char ptr in The keyword string to match
defaul long in The default value to return if
no keyword or illegal value
p_value long ptr out The returned value
p_flag int ptr out The flag: -1 for no keyword match
0 for keyword with no/bad value
1 for keyword and good value

***/

{
char stringvalue[80];

ExtractKeywordString (CommandString, Keyword, p_flag, stringvalue);
if (*p_flag == 1)
{
if (sscanf (stringvalue, "%ld", p_value) == 0)
{
*p_flag = 0;
*p_value = defaul;
}
}
else
{
*p_value = defaul;
}
}

int GetKeywordReal (char * CommandString, char * Keyword, float defaul,
float * p_value, int * p_flag)

/*** GetKeywordReal scans the CommandString for the Keyword and returns
the value of the following real.

Parameter Type In/out Description
CommandString char ptr in The command string to scan thru
Keyword char ptr in The keyword string to match
defaul float in The default value to return if
no keyword or illegal value
p_value float ptr out The returned value
p_flag int ptr out The flag: -1 for no keyword match
0 for keyword with no/bad value
1 for keyword and good value

***/
{
char stringvalue[80];

ExtractKeywordString (CommandString, Keyword, p_flag, stringvalue);
if (*p_flag == 1)
{
if (sscanf (stringvalue, "%f", p_value) == 0)
{
*p_flag = 0;
*p_value = defaul;
}
}
else
{
*p_value = defaul;
}
}

int GetKeywordString (char * CommandString, char * Keyword, char * defaul,
char * value, int * p_flag)

/*** GetKeywordString scans the CommandString for the Keyword
and returns the value of the following string.

Parameter Type In/out Description
CommandString char ptr in The command string to scan thru
Keyword char ptr in The keyword string to match
defaul char ptr in The default value to return if
no keyword or illegal value
value char ptr out The returned value
p_flag int ptr out The flag: -1 for no keyword match
0 for keyword with no/bad value
1 for keyword and good value

***/

{
char stringvalue[255];

ExtractKeywordString (CommandString, Keyword, p_flag, stringvalue);
if (*p_flag == 1)
{
strcpy (value, stringvalue);
}
else
{
strcpy (value, defaul);
}
}


int GetKeywordSubcommand (char * CommandString, char * Keyword, int * p_flag)

/*** GetKeywordSubcommand scans the CommandString for the Keyword
and returns the value of the following string.

Parameter Type In/out Description
CommandString char ptr in The command string to scan thru
Keyword char ptr in The keyword string to match
p_flag int ptr out The flag: -1 for no keyword match
1 for keyword found

***/

{
int j;
char *searchptr;


/* Find where the keyword is in the buffer */
searchptr = strstr (CommandString, Keyword);
j = searchptr - CommandString;

if ( (searchptr == NULL) || ((j > 0) && (CommandString[j-1] > ' ')) )
*p_flag = -1;
else
{
*p_flag = 1;
}
}


  3 Responses to “Category : C Source Code
Archive   : IMDSRC78.ZIP
Filename : KEYWUTIL.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/