source: trunk/third/transcript/src/printpanel/readfax.c @ 9090

Revision 9090, 2.6 KB checked in by ghudson, 28 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r9089, which included commits to RCS files with non-trunk default branches.
Line 
1/*
2 * Copyright (C) 1992 Adobe Systems Incorporated.  All rights reserved.
3 *
4 * RCSID: $Header: /afs/dev.mit.edu/source/repository/third/transcript/src/printpanel/readfax.c,v 1.1.1.1 1996-10-07 20:25:55 ghudson Exp $
5 *
6 * RCSLog:
7 * $Log: not supported by cvs2svn $
8 * Revision 4.0  1992/08/21  16:24:13  snichols
9 * Release 4.0
10 *
11 * Revision 1.5  1992/07/14  23:08:22  snichols
12 * Added copyright.
13 *
14 *
15 */
16#include <stdio.h>
17#ifdef XPG3
18#include <stdlib.h>
19#else
20#include "../compat.h"
21#endif
22#include <string.h>
23
24#define TRUE 1
25#define FALSE 0
26
27struct FaxPhoneEntry {
28    char option[200];
29    char value[200];
30};
31
32int GetPhonebookKeys(klist, nkeys, maxkeys, filename)
33    char *klist[];
34    int *nkeys;
35    int *maxkeys;
36    char *filename;
37{
38    FILE *fp;
39    char buf[1024];
40    char *p;
41    int inentry = FALSE;
42    int i;
43
44    if ((fp = fopen(filename, "r")) == NULL)
45        return -1;
46
47    i = 0;
48
49    while (fgets(buf, 1024, fp)) {
50        if (buf[0] == '%')
51            continue;
52        if (inentry) {
53            if (buf[0] == '.')
54                inentry = FALSE;
55            continue;
56        }
57        if ((p = (char *)strchr(buf, '\n')) != NULL)
58            *p = '\0';
59        klist[i] = (char *) malloc(strlen(buf)+1);
60        strcpy(klist[i], buf);
61        i++;
62        inentry = TRUE;
63    }
64    *nkeys = i;
65    close(fp);
66    return 0;
67}
68
69static int HandlePhoneOption(line, list, numlist, maxlist)
70    char *line;
71    struct FaxPhoneEntry list[];
72    int *numlist, *maxlist;
73{
74    char *p, *q;
75
76     p = strchr(line, '=');
77    if (p == NULL) {
78        p = strchr(line, ':');
79        if (p == NULL)
80            return -1;
81    }
82    *p = '\0';
83    p++;
84    while (*p == ' ') p++;
85    if (line[0] == '/') {
86        /* special keyword */
87        return -2; /* for now */
88    }
89    else {
90        if (*numlist >= *maxlist) {
91            list = (struct FaxPhoneEntry *)
92                realloc(list, 10*sizeof(struct FaxPhoneEntry)); 
93            *maxlist += 10;
94        }
95        strcpy(list[*numlist].option, line);
96        strcpy(list[*numlist].value, p);
97        (*numlist)++;
98    }
99}
100   
101
102int FindPhoneEntry(key, entlist, nentries, maxentries, dbfile)
103    char *key;
104    struct FaxPhoneEntry entlist[];
105    int *nentries, *maxentries;
106    char *dbfile;
107{
108    FILE *fp;
109    char buf[1024];
110    char *p;
111
112    if ((fp = fopen(dbfile, "r")) == NULL) {
113        fprintf(stderr, "couldn't open %s\n", dbfile);
114        return 0;
115    }
116    while (fgets(buf, 1024, fp)) {
117        if (buf[0] == '%')
118            continue;
119        p = strchr(buf, '\n');
120        if (p) *p = '\0';
121        if (strcmp(buf, key) == 0) {
122            while (fgets(buf, 1024, fp)) {
123                p = strchr(buf, '\n');
124                if (p) *p = '\0';
125                if (buf[0] == '%')
126                    continue;
127                if (buf[0] == '.')
128                    break;
129                HandlePhoneOption(buf, entlist, nentries, maxentries);
130            }
131        }
132    }
133    return 1;
134}
Note: See TracBrowser for help on using the repository browser.