2010-09-28 12:40:11 +00:00
|
|
|
#include "QF/dstring.h"
|
|
|
|
#include "QF/va.h"
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-11 08:35:25 +00:00
|
|
|
#include "Dict.h"
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
@implementation Dict
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-init
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
[super initCount: 0 elementSize:sizeof (dict_t)
|
|
|
|
description:NULL];
|
|
|
|
return self;
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-print
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
int i;
|
|
|
|
dict_t *d;
|
|
|
|
|
|
|
|
for (i = 0; i < numElements; i++) {
|
|
|
|
d =[self elementAt:i];
|
|
|
|
printf ("%s : %s\n", d->key, d->value);
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===========
|
|
|
|
copyFromZone
|
|
|
|
|
|
|
|
JDC
|
|
|
|
===========
|
|
|
|
*/
|
2010-09-11 10:03:41 +00:00
|
|
|
-copy
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
id new;
|
|
|
|
int i;
|
|
|
|
dict_t *d;
|
|
|
|
char *old;
|
|
|
|
|
|
|
|
new =[super copy];
|
|
|
|
for (i = 0; i < numElements; i++) {
|
|
|
|
d =[self elementAt:i];
|
2003-03-18 19:48:24 +00:00
|
|
|
old = d->key;
|
2010-09-11 10:03:41 +00:00
|
|
|
d->key = malloc (strlen (old) + 1);
|
2003-03-18 19:48:24 +00:00
|
|
|
strcpy (d->key, old);
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
old = d->value;
|
2010-09-11 10:03:41 +00:00
|
|
|
d->value = malloc (strlen (old) + 1);
|
2003-03-18 19:48:24 +00:00
|
|
|
strcpy (d->value, old);
|
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-initFromFile:(FILE *) fp
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
|
|
|
[self init];
|
2010-09-11 10:03:41 +00:00
|
|
|
return[self parseBraceBlock:fp];
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===============================================
|
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
// Dictionary pair functions
|
2003-03-18 19:48:24 +00:00
|
|
|
//
|
|
|
|
//===============================================
|
|
|
|
|
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
// Write a { } block out to a FILE*
|
2003-03-18 19:48:24 +00:00
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
-writeBlockTo:(FILE *) fp
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
int max;
|
|
|
|
int i;
|
|
|
|
dict_t *d;
|
|
|
|
|
|
|
|
fprintf (fp, "{\n");
|
|
|
|
max =[super count];
|
|
|
|
for (i = 0; i < max; i++) {
|
|
|
|
d =[super elementAt:i];
|
|
|
|
fprintf (fp, "\t{\"%s\"\t\"%s\"}\n", d->key, d->value);
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
fprintf (fp, "}\n");
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
// Write a single { } block out
|
2003-03-18 19:48:24 +00:00
|
|
|
//
|
2010-09-28 09:41:38 +00:00
|
|
|
-writeFile:(const char *) path
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
fp = fopen (path, "w+t");
|
|
|
|
if (fp != NULL) {
|
|
|
|
printf ("Writing dictionary file %s.\n", path);
|
|
|
|
fprintf (fp, "// QE_Project file %s\n", path);
|
2003-03-18 19:48:24 +00:00
|
|
|
[self writeBlockTo:fp];
|
2010-09-11 10:03:41 +00:00
|
|
|
fclose (fp);
|
|
|
|
} else {
|
|
|
|
printf ("Error writing %s!\n", path);
|
2003-03-18 19:48:24 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===============================================
|
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
// Utility methods
|
2003-03-18 19:48:24 +00:00
|
|
|
//
|
|
|
|
//===============================================
|
|
|
|
|
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
// Find a keyword in storage
|
|
|
|
// Returns * to dict_t, otherwise NULL
|
2003-03-18 19:48:24 +00:00
|
|
|
//
|
2010-09-28 09:41:38 +00:00
|
|
|
-(dict_t *) findKeyword:(const char *) key
|
2010-09-11 10:03:41 +00:00
|
|
|
{
|
|
|
|
int max;
|
|
|
|
int i;
|
|
|
|
dict_t *d;
|
|
|
|
|
|
|
|
max =[super count];
|
|
|
|
for (i = 0; i < max; i++) {
|
|
|
|
d =[super elementAt:i];
|
|
|
|
if (!strcmp (d->key, key))
|
2003-03-18 19:48:24 +00:00
|
|
|
return d;
|
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
// Change a keyword's string
|
2003-03-18 19:48:24 +00:00
|
|
|
//
|
2010-09-28 09:41:38 +00:00
|
|
|
-changeStringFor:(const char *) key to:(const char *) value
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
dict_t *d;
|
|
|
|
dict_t newd;
|
|
|
|
|
|
|
|
d =[self findKeyword:key];
|
|
|
|
if (d != NULL) {
|
|
|
|
free (d->value);
|
|
|
|
d->value = malloc (strlen (value) + 1);
|
|
|
|
strcpy (d->value, value);
|
|
|
|
} else {
|
|
|
|
newd.key = malloc (strlen (key) + 1);
|
|
|
|
strcpy (newd.key, key);
|
|
|
|
newd.value = malloc (strlen (value) + 1);
|
|
|
|
strcpy (newd.value, value);
|
2003-03-18 19:48:24 +00:00
|
|
|
[self addElement:&newd];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
// Search for keyword, return the string *
|
2003-03-18 19:48:24 +00:00
|
|
|
//
|
2010-09-28 09:41:38 +00:00
|
|
|
-(const char *) getStringFor:(const char *) name
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
dict_t *d;
|
|
|
|
|
|
|
|
d =[self findKeyword:name];
|
2003-03-18 19:48:24 +00:00
|
|
|
if (d != NULL)
|
|
|
|
return d->value;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
// Search for keyword, return the value
|
2003-03-18 19:48:24 +00:00
|
|
|
//
|
2010-09-28 09:41:38 +00:00
|
|
|
-(unsigned int) getValueFor:(const char *) name
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
dict_t *d;
|
|
|
|
|
|
|
|
d =[self findKeyword:name];
|
2003-03-18 19:48:24 +00:00
|
|
|
if (d != NULL)
|
2010-09-11 10:03:41 +00:00
|
|
|
return atol (d->value);
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
// Return # of units in keyword's value
|
2003-03-18 19:48:24 +00:00
|
|
|
//
|
2010-09-28 09:41:38 +00:00
|
|
|
-(int) getValueUnits:(const char *) key
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
id temp;
|
|
|
|
int count;
|
|
|
|
|
|
|
|
temp =[self parseMultipleFrom:key];
|
|
|
|
count =[temp count];
|
2010-09-11 08:35:25 +00:00
|
|
|
[temp release];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
// Convert List to string
|
2003-03-18 19:48:24 +00:00
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
-(char *) convertListToString:(id) list
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
int i;
|
|
|
|
int max;
|
2010-09-28 12:40:11 +00:00
|
|
|
dstring_t *tempstr;
|
2010-09-11 10:03:41 +00:00
|
|
|
char *s;
|
|
|
|
|
|
|
|
max =[list count];
|
2010-09-28 12:40:11 +00:00
|
|
|
tempstr = dstring_newstr ();
|
2010-09-11 10:03:41 +00:00
|
|
|
for (i = 0; i < max; i++) {
|
|
|
|
s =[list elementAt:i];
|
2010-09-28 12:40:11 +00:00
|
|
|
dstring_appendstr (tempstr, s);
|
|
|
|
dstring_appendstr (tempstr, " ");
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2010-09-28 12:40:11 +00:00
|
|
|
return dstring_freeze (tempstr);
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// JDC: I wrote this to simplify removing vectors
|
|
|
|
//
|
2010-09-28 09:41:38 +00:00
|
|
|
-removeKeyword:(const char *) key
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
dict_t *d;
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
d =[self findKeyword:key];
|
2003-03-18 19:48:24 +00:00
|
|
|
if (d == NULL)
|
|
|
|
return self;
|
2010-09-11 10:03:41 +00:00
|
|
|
[self removeElementAt:d - (dict_t *) dataPtr];
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
// Delete string from keyword's value
|
2003-03-18 19:48:24 +00:00
|
|
|
//
|
2010-09-28 09:41:38 +00:00
|
|
|
-delString:(const char *) string fromValue:(const char *) key
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
id temp;
|
|
|
|
int count;
|
|
|
|
int i;
|
|
|
|
char *s;
|
|
|
|
dict_t *d;
|
|
|
|
|
|
|
|
d =[self findKeyword:key];
|
2003-03-18 19:48:24 +00:00
|
|
|
if (d == NULL)
|
|
|
|
return NULL;
|
2010-09-11 10:03:41 +00:00
|
|
|
temp =[self parseMultipleFrom:key];
|
|
|
|
count =[temp count];
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
s =[temp elementAt:i];
|
|
|
|
if (!strcmp (s, string)) {
|
2003-03-18 19:48:24 +00:00
|
|
|
[temp removeElementAt:i];
|
2010-09-11 10:03:41 +00:00
|
|
|
free (d->value);
|
|
|
|
d->value =[self convertListToString:temp];
|
2010-09-11 08:35:25 +00:00
|
|
|
[temp release];
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
// Add string to keyword's value
|
2003-03-18 19:48:24 +00:00
|
|
|
//
|
2010-09-28 09:41:38 +00:00
|
|
|
-addString:(const char *) string toValue:(const char *) key
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
char *newstr;
|
|
|
|
dict_t *d;
|
|
|
|
|
|
|
|
d =[self findKeyword:key];
|
2003-03-18 19:48:24 +00:00
|
|
|
if (d == NULL)
|
|
|
|
return NULL;
|
2010-09-28 12:40:11 +00:00
|
|
|
newstr = nva ("%s\t%s", d->value, string);
|
2010-09-11 10:03:41 +00:00
|
|
|
free (d->value);
|
2003-03-18 19:48:24 +00:00
|
|
|
d->value = newstr;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===============================================
|
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
// Use these for multiple parameters in a keyword value
|
2003-03-18 19:48:24 +00:00
|
|
|
//
|
|
|
|
//===============================================
|
2010-09-28 09:41:38 +00:00
|
|
|
const char *searchStr;
|
2010-09-11 10:03:41 +00:00
|
|
|
char item[4096];
|
2003-03-18 19:48:24 +00:00
|
|
|
|
2010-09-28 09:41:38 +00:00
|
|
|
-setupMultiple:(const char *) value
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
|
|
|
searchStr = value;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
-(char *) getNextParameter
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
char *s;
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
if (!searchStr)
|
|
|
|
return NULL;
|
2010-09-11 10:03:41 +00:00
|
|
|
strcpy (item, searchStr);
|
|
|
|
s = FindWhitespcInBuffer (item);
|
2003-03-18 19:48:24 +00:00
|
|
|
if (!*s)
|
|
|
|
searchStr = NULL;
|
2010-09-11 10:03:41 +00:00
|
|
|
else {
|
2003-03-18 19:48:24 +00:00
|
|
|
*s = 0;
|
2010-09-11 10:03:41 +00:00
|
|
|
searchStr = FindNonwhitespcInBuffer (s + 1);
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
// Parses a keyvalue string & returns a Storage full of those items
|
2003-03-18 19:48:24 +00:00
|
|
|
//
|
2010-09-28 09:41:38 +00:00
|
|
|
-(id) parseMultipleFrom:(const char *) key
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
#define ITEMSIZE 128
|
|
|
|
id stuff;
|
|
|
|
char string[ITEMSIZE];
|
2010-09-28 09:41:38 +00:00
|
|
|
const char *s;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
s =[self getStringFor:key];
|
2003-03-18 19:48:24 +00:00
|
|
|
if (s == NULL)
|
|
|
|
return NULL;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
stuff =[[Storage alloc]
|
|
|
|
initCount: 0 elementSize: ITEMSIZE description:NULL];
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
[self setupMultiple:s];
|
2010-09-11 10:03:41 +00:00
|
|
|
while ((s =[self getNextParameter])) {
|
|
|
|
bzero (string, ITEMSIZE);
|
|
|
|
strcpy (string, s);
|
2003-03-18 19:48:24 +00:00
|
|
|
[stuff addElement:string];
|
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return stuff;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===============================================
|
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
// Dictionary pair parsing
|
2003-03-18 19:48:24 +00:00
|
|
|
//
|
|
|
|
//===============================================
|
|
|
|
|
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
// parse all keyword/value pairs within { } 's
|
2003-03-18 19:48:24 +00:00
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
-(id) parseBraceBlock:(FILE *) fp
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
int c;
|
|
|
|
dict_t pair;
|
|
|
|
char string[1024];
|
|
|
|
|
|
|
|
c = FindBrace (fp);
|
2003-03-18 19:48:24 +00:00
|
|
|
if (c == -1)
|
|
|
|
return NULL;
|
2010-09-11 10:03:41 +00:00
|
|
|
|
|
|
|
while ((c = FindBrace (fp)) != '}') {
|
2003-03-18 19:48:24 +00:00
|
|
|
if (c == -1)
|
|
|
|
return NULL;
|
2010-09-11 10:03:41 +00:00
|
|
|
// c = FindNonwhitespc(fp);
|
|
|
|
// if (c == -1)
|
|
|
|
// return NULL;
|
|
|
|
// CopyUntilWhitespc(fp,string);
|
2003-03-18 19:48:24 +00:00
|
|
|
|
|
|
|
// JDC: fixed to allow quoted keys
|
2010-09-11 10:03:41 +00:00
|
|
|
c = FindNonwhitespc (fp);
|
2003-03-18 19:48:24 +00:00
|
|
|
if (c == -1)
|
|
|
|
return NULL;
|
2010-09-11 10:03:41 +00:00
|
|
|
c = fgetc (fp);
|
|
|
|
if (c == '\"')
|
|
|
|
CopyUntilQuote (fp, string);
|
|
|
|
else {
|
|
|
|
ungetc (c, fp);
|
|
|
|
CopyUntilWhitespc (fp, string);
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
pair.key = malloc (strlen (string) + 1);
|
|
|
|
strcpy (pair.key, string);
|
|
|
|
|
|
|
|
c = FindQuote (fp);
|
|
|
|
CopyUntilQuote (fp, string);
|
|
|
|
pair.value = malloc (strlen (string) + 1);
|
|
|
|
strcpy (pair.value, string);
|
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
[super addElement:&pair];
|
2010-09-11 10:03:41 +00:00
|
|
|
c = FindBrace (fp);
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
|
2003-03-18 19:48:24 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
//===============================================
|
|
|
|
//
|
2010-09-11 10:03:41 +00:00
|
|
|
// C routines for string parsing
|
2003-03-18 19:48:24 +00:00
|
|
|
//
|
|
|
|
//===============================================
|
2010-09-11 10:03:41 +00:00
|
|
|
int
|
|
|
|
GetNextChar (FILE * fp)
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
int c;
|
|
|
|
int c2;
|
|
|
|
|
|
|
|
c = getc (fp);
|
2003-03-18 19:48:24 +00:00
|
|
|
if (c == EOF)
|
|
|
|
return -1;
|
2010-09-11 10:03:41 +00:00
|
|
|
if (c == '/') // parse comments
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
c2 = getc (fp);
|
|
|
|
if (c2 == '/') {
|
|
|
|
while ((c2 = getc (fp)) != '\n');
|
|
|
|
c = getc (fp);
|
|
|
|
} else
|
|
|
|
ungetc (c2, fp);
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
void
|
|
|
|
CopyUntilWhitespc (FILE * fp, char *buffer)
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
int count = 800;
|
|
|
|
int c;
|
|
|
|
|
|
|
|
while (count--) {
|
|
|
|
c = GetNextChar (fp);
|
2003-03-18 19:48:24 +00:00
|
|
|
if (c == EOF)
|
|
|
|
return;
|
2010-09-11 10:03:41 +00:00
|
|
|
if (c <= ' ') {
|
2003-03-18 19:48:24 +00:00
|
|
|
*buffer = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
*buffer++ = c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
void
|
|
|
|
CopyUntilQuote (FILE * fp, char *buffer)
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
int count = 800;
|
|
|
|
int c;
|
|
|
|
|
|
|
|
while (count--) {
|
|
|
|
c = GetNextChar (fp);
|
2003-03-18 19:48:24 +00:00
|
|
|
if (c == EOF)
|
|
|
|
return;
|
2010-09-11 10:03:41 +00:00
|
|
|
if (c == '\"') {
|
2003-03-18 19:48:24 +00:00
|
|
|
*buffer = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
*buffer++ = c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
int
|
|
|
|
FindBrace (FILE * fp)
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
int count = 800;
|
|
|
|
int c;
|
|
|
|
|
|
|
|
while (count--) {
|
|
|
|
c = GetNextChar (fp);
|
2003-03-18 19:48:24 +00:00
|
|
|
if (c == EOF)
|
|
|
|
return -1;
|
2010-09-11 10:03:41 +00:00
|
|
|
if (c == '{' || c == '}')
|
2003-03-18 19:48:24 +00:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
int
|
|
|
|
FindQuote (FILE * fp)
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
int count = 800;
|
|
|
|
int c;
|
|
|
|
|
|
|
|
while (count--) {
|
|
|
|
c = GetNextChar (fp);
|
2003-03-18 19:48:24 +00:00
|
|
|
if (c == EOF)
|
|
|
|
return -1;
|
|
|
|
if (c == '\"')
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
int
|
|
|
|
FindWhitespc (FILE * fp)
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
int count = 800;
|
|
|
|
int c;
|
|
|
|
|
|
|
|
while (count--) {
|
|
|
|
c = GetNextChar (fp);
|
2003-03-18 19:48:24 +00:00
|
|
|
if (c == EOF)
|
|
|
|
return -1;
|
2010-09-11 10:03:41 +00:00
|
|
|
if (c <= ' ') {
|
|
|
|
ungetc (c, fp);
|
2003-03-18 19:48:24 +00:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
}
|
2010-09-11 10:03:41 +00:00
|
|
|
return -1;
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
int
|
|
|
|
FindNonwhitespc (FILE * fp)
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
int count = 800;
|
|
|
|
int c;
|
|
|
|
|
|
|
|
while (count--) {
|
|
|
|
c = GetNextChar (fp);
|
2003-03-18 19:48:24 +00:00
|
|
|
if (c == EOF)
|
|
|
|
return -1;
|
2010-09-11 10:03:41 +00:00
|
|
|
if (c > ' ') {
|
|
|
|
ungetc (c, fp);
|
2003-03-18 19:48:24 +00:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
char *
|
|
|
|
FindWhitespcInBuffer (char *buffer)
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
int count = 1000;
|
|
|
|
char *b = buffer;
|
|
|
|
|
|
|
|
while (count--)
|
2003-03-18 19:48:24 +00:00
|
|
|
if (*b <= ' ')
|
|
|
|
return b;
|
|
|
|
else
|
|
|
|
b++;
|
2010-09-11 10:03:41 +00:00
|
|
|
return NULL;
|
2003-03-18 19:48:24 +00:00
|
|
|
}
|
|
|
|
|
2010-09-11 10:03:41 +00:00
|
|
|
char *
|
|
|
|
FindNonwhitespcInBuffer (char *buffer)
|
2003-03-18 19:48:24 +00:00
|
|
|
{
|
2010-09-11 10:03:41 +00:00
|
|
|
int count = 1000;
|
|
|
|
char *b = buffer;
|
|
|
|
|
|
|
|
while (count--)
|
2003-03-18 19:48:24 +00:00
|
|
|
if (*b > ' ')
|
|
|
|
return b;
|
|
|
|
else
|
|
|
|
b++;
|
|
|
|
return NULL;
|
|
|
|
}
|