home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 5
/
FreshFish_July-August1994.bin
/
tools
/
pitools
/
pi2loaddb.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-04-07
|
6KB
|
292 lines
/*
* pi2loaddb - Create LoadDB input file from a Product-Info file.
*
*
* Note that this program assumes that all of the field names are in lower
* case.
*/
/*
* Written by: David W. Lowrey
* Starbound Enterprises
*/
static char RCS_ID[] = {
" $Id: prodinfo.c,v 1.3 1994/01/30 16:00:01 D_Lowrey Exp $ "
};
#include <stdio.h>
#include <string.h>
void clean_string (char *, char *);
void do_it (FILE *);
char storage[10000][200]; /* !! ACK - CHOKE !! */
char volume[256];
unsigned int name, version, stored_in, type, short_desc,desc_start,desc_end;
unsigned int req_start, req_end, ref_start, ref_end, dist_start, dist_end;
unsigned int auth_start, auth_end;
int VolNameFlag;
int main(argc, argv)
int argc;
char *argv[];
{
int errflg = 0;
int ch;
FILE *fin;
extern int optind;
extern char *optarg;
while ((ch = getopt (argc, argv, "hV")) != EOF)
{
switch (ch)
{
case 'V':
VolNameFlag++;
break;
case 'h':
break;
case '?':
errflg++;
break;
default:
errflg++;
break;
}
if (errflg)
{
fprintf (stderr, "unknown arg, use -h for help\n");
exit (1);
}
}
if (optind == argc)
{
do_it (stdin);
}
else
{
for ( ; optind < argc; optind++)
{
fin = fopen (argv[optind], "r");
if (fin == NULL)
{
perror (argv[optind]);
}
else
{
do_it (fin);
fclose (fin);
}
}
}
exit (0);
return (0);
}
void
do_it (fin)
FILE *fin;
{
char line[512];
char *ptr;
unsigned int *end_ptr = NULL;
char fields[10][13] = {
"name","version","stored-in","type","short","description",
"requirements","reference","distribution","author"
};
unsigned int lens[10] = {4, 7, 4, 4, 5, 11, 12, 9, 12, 6};
unsigned int field_num = 0;
unsigned int storage_line;
int i, len;
int processed_field;
unsigned started = 0;
void print_record(void);
while (fgets (line, sizeof (line), fin))
{
line[strlen (line) - 1] = '\000';
if(line[0] == '.')
{
if(started && (!strncmp(line,".name",5)))
{
print_record();
started = 0;
}
if (!started)
{
version=stored_in=type=short_desc=desc_start=desc_end=0;
req_start=req_end=ref_start=ref_end=dist_start=dist_end=0;
name=auth_start=auth_end=0;
volume[0] = '\0';
storage_line = 1;
started = 1;
}
processed_field = 0;
if (end_ptr)
*end_ptr = storage_line - 1;
field_num = 0;
for(i=0; i<10; i++)
{
if (!strncmp(&line[1], fields[i], lens[i]))
{
field_num = i+1;
break;
}
}
}
else if (started)
if(processed_field)
clean_string(line, storage[storage_line++]);
else
{
++processed_field;
switch(field_num)
{
case 0: /* Non-used field */
processed_field = 0;
break;
case 1: /* .name */
clean_string(line, storage[storage_line]);
name=storage_line++;
end_ptr = NULL;
break;
case 2: /* .version */
clean_string(line, storage[storage_line]);
version=storage_line++;
end_ptr = NULL;
break;
case 3: /* .stored-in */
clean_string(line, storage[storage_line]);
stored_in=storage_line++;
ptr = (char *)strchr(storage[stored_in], (int)':');
if(ptr) {
len = ptr-storage[stored_in];
strncpy(volume,storage[stored_in],(size_t)len);
volume[len] = '\0';
}
end_ptr = NULL;
break;
case 4: /* .type */
clean_string(line, storage[storage_line]);
type=storage_line++;
end_ptr = NULL;
break;
case 5: /* .short */
clean_string(line, storage[storage_line]);
short_desc=storage_line++;
end_ptr = NULL;
break;
case 6: /* .description */
clean_string(line, storage[storage_line]);
desc_start=storage_line++;
end_ptr = &desc_end;
break;
case 7: /* .requirements */
clean_string(line, storage[storage_line]);
req_start=storage_line++;
end_ptr = &req_end;
break;
case 8: /* .reference */
clean_string(line, storage[storage_line]);
ref_start=storage_line++;
end_ptr = &ref_end;
break;
case 9: /* .distribution */
clean_string(line, storage[storage_line]);
dist_start=storage_line++;
end_ptr = &dist_end;
break;
case 10: /* .author */
clean_string(line, storage[storage_line]);
auth_start=storage_line++;
end_ptr = &auth_end;
break;
}
}
}
if (end_ptr)
*end_ptr = storage_line - 1;
print_record();
}
void clean_string(char *src, char *dest)
{
char *ptr;
for (ptr=src; *ptr == ' '; ptr++); /* Find first non blank */
strcpy (dest, ptr);
ptr = (char *)(dest + strlen(dest) - 1);
for (; *ptr == ' '; ptr--); /* Find last non blank */
*(++ptr) = '\0';
}
void print_record()
{
int i;
storage[0][0] = '\0';
printf ("#R\n");
printf ("#H %s", storage[name]);
if (version)
printf (" %s", storage[version]);
if (VolNameFlag)
{
printf (" %s", volume);
}
printf ("\n");
printf ("#K %s\n", storage[name]);
printf ("#K %s\n", volume);
if (type)
printf ("#K %s\n", storage[type]);
if (short_desc)
printf ("%s\n\n", storage[short_desc]);
if (desc_start)
{
for(i=desc_start; i<= desc_end; i++)
printf ("%s\n", storage[i]);
printf ("\n");
}
if (req_start)
{
for(i=req_start; i<= req_end; i++)
printf ("%s\n", storage[i]);
printf ("\n");
}
if (stored_in)
{
printf ("#TTHIS VERSION:\n");
if (version)
printf ("%s\t%s\n\n", storage[version], storage[stored_in]);
else
printf ("?.?\t%s\n\n", storage[stored_in]);
}
if(ref_start)
{
printf ("#TOTHER VERSIONS:\n");
for(i=ref_start; i<ref_end; i+=2) {
#if 0
if (storage[i][strlen(storage[i])-1] == '/')
storage[i][strlen(storage[i])-1] = '\0';
#endif
printf ("%s\t%s\n", storage[i+1], storage[i]);
}
printf ("\n");
}
if(dist_start)
{
printf ("#TDISTRIBUTION:\n");
for(i=dist_start; i<= dist_end; i++)
printf ("%s\n", storage[i]);
printf ("\n");
}
if(auth_start)
{
printf ("#TAUTHOR:\n");
for(i=auth_start; i<= auth_end; i++)
printf ("%s\n", storage[i]);
}
}