00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef lint
00037 static const char libbu_association_RCSid[] = "@(#)$Header: /cvsroot/brlcad/brlcad/src/libbu/association.c,v 14.14 2006/08/31 23:16:38 lbutler Exp $ (ARL)";
00038 #endif
00039
00040 #include "common.h"
00041
00042 #include <stdlib.h>
00043 #include <stdio.h>
00044 #include <math.h>
00045 #if HAVE_STRING_H
00046 # include <string.h>
00047 #endif
00048
00049 #include "machine.h"
00050 #include "bu.h"
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 struct bu_vls *
00068 bu_association (const char *fname,
00069 const char *value,
00070 int field_sep)
00071 {
00072 char *cp;
00073 FILE *fp;
00074 size_t len;
00075 struct bu_vls *vp = 0;
00076 struct bu_vls buffer;
00077
00078
00079
00080 if ((fp = fopen(fname, "r")) == NULL) {
00081
00082
00083
00084
00085
00086
00087
00088 bu_log("bu_association: Cannot open association file '%s'\n", fname);
00089 exit (1);
00090 }
00091
00092 bu_vls_init(&buffer);
00093 len = strlen(value);
00094
00095 do {
00096 bu_vls_trunc(&buffer, 0);
00097 if (bu_vls_gets(&buffer, fp) == -1)
00098 goto wrap_up;
00099 cp = bu_vls_addr(&buffer);
00100
00101 } while ((*cp != *value) || (*(cp + len) != field_sep)
00102 || (strncmp(cp, value, len) != 0));
00103
00104 vp = (struct bu_vls *) bu_malloc(sizeof(struct bu_vls), "value of bu_association");
00105 bu_vls_init(vp);
00106 bu_vls_strcpy(vp, cp + len + 1);
00107
00108 wrap_up:
00109 bu_vls_trunc(&buffer, 0);
00110 fclose(fp);
00111 return (vp);
00112 }
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122