1 /*****************************************************************************/
2 /*                                                                           */
3 /*                 (C) Copyright 1991-1995  Alberto Pasquale                 */
4 /*                 Portions (C) Copyright 1999 Per Lundberg                  */
5 /*                                                                           */
6 /*                   A L L   R I G H T S   R E S E R V E D                   */
7 /*                                                                           */
8 /*****************************************************************************/
9 /*                                                                           */
10 /*   How to contact the author:  Alberto Pasquale of 2:332/504@fidonet       */
11 /*                               Viale Verdi 106                             */
12 /*                               41100 Modena                                */
13 /*                               Italy                                       */
14 /*                                                                           */
15 /*****************************************************************************/
16 
17 // StrLst.Cpp
18 
19 #include "bbsgenlb.hpp"
20 #include <apgenlib.hpp>
21 #include <string.h>
22 
StrLst(char * OutNameCfg,BOOL Append,char * OutName)23 StrLst::StrLst (char *OutNameCfg, BOOL Append, char *OutName)
24 {
25     StrLst::OutNameCfg = newcpy (OutNameCfg);
26     StrLst::Append = Append;
27     if (OutName && *OutName)
28         StrLst::OutName = newcpy (OutName);
29     else
30         StrLst::OutName = NULL;
31     Outf = NULL;
32 }
33 
34 
~StrLst(void)35 StrLst::~StrLst (void)
36 {
37     delete[] OutNameCfg;
38     if (OutName)
39         delete[] OutName;
40     if (Outf)
41         Close ();
42 }
43 
44 
SetDefCfg(char * OutName)45 void StrLst::SetDefCfg (char *OutName)
46 {
47     if (!StrLst::OutName && *OutName)
48         StrLst::OutName = newcpy (OutName);
49 }
50 
51 
ParseCfg(const char * clnline)52 BOOL StrLst::ParseCfg (const char *clnline)
53 {
54     const char *tkp = clnline;
55     char *tok = GetStatName (tkp);
56 
57     if (!tok)
58         return FALSE;
59 
60     if (stricmp (tok, OutNameCfg) ==  0) {
61         if (*tkp == '+') {
62             Append = TRUE;
63             tkp ++;
64         }
65         if (OutName)
66             delete[] OutName;
67         OutName = GetAllocName (tkp);
68         return TRUE;
69     }
70 
71     return FALSE;
72 }
73 
74 
Add(const char * tag)75 int StrLst::Add (const char *tag)
76 {
77     if (!OutName)
78         return 0;
79 
80     if (!Outf) {
81         Outf = fopen (OutName, Append ? "at" : "wt");
82         if (!Outf)
83             return -1;
84     }
85 
86     if (fprintf (Outf, "%s\n", tag) < 0)
87         return -1;
88 
89     return 0;
90 }
91 
92 
Close(void)93 int StrLst::Close (void)
94 {
95     if (Outf) {
96         if (fclose (Outf))
97             return -1;
98         Outf = NULL;
99     }
100     return 0;
101 }
102