| 1 |
/* File: longtext.c |
| 2 |
* Author: Jean Thierry-Mieg ([email protected]) |
| 3 |
* Copyright (C) J Thierry-Mieg and R Durbin, 1992 |
| 4 |
* ------------------------------------------------------------------- |
| 5 |
* Acedb is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU General Public License |
| 7 |
* as published by the Free Software Foundation; either version 2 |
| 8 |
* of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this program; if not, write to the Free Software |
| 17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 18 |
* or see the on-line version at http://www.gnu.org/copyleft/gpl.txt |
| 19 |
* ------------------------------------------------------------------- |
| 20 |
* This file is part of the ACEDB genome database package, written by |
| 21 |
* Richard Durbin (MRC LMB, UK) [email protected], and |
| 22 |
* Jean Thierry-Mieg (CRBM du CNRS, France) [email protected] |
| 23 |
* |
| 24 |
* Description: ace-kernel functions to handle longtext data |
| 25 |
* Exported functions: |
| 26 |
* HISTORY: |
| 27 |
* Last edited: Nov 30 17:59 2001 (edgrif) |
| 28 |
* * Sep 15 15:22 1999 (fw): srk patch parsing empty longtext object |
| 29 |
* deletes associated object |
| 30 |
* * Jan 28 09:19 1999 (fw): moved graphical part to longtextdisp.c |
| 31 |
* * Oct 15 15:18 1992 (mieg): Editing |
| 32 |
* Created: Fri Mar 13 15:06:53 1992 (mieg) |
| 33 |
*------------------------------------------------------------------- |
| 34 |
*/ |
| 35 |
|
| 36 |
/* $Id: longtext.c,v 1.36 2001/12/03 11:08:57 edgrif Exp $ */ |
| 37 |
|
| 38 |
#include "acedb.h" |
| 39 |
#include "aceio.h" |
| 40 |
#include <ctype.h> |
| 41 |
#include "a.h" |
| 42 |
#include "lex.h" |
| 43 |
#include "whooks/sysclass.h" |
| 44 |
#include "whooks/classes.h" |
| 45 |
#include "pick.h" /* needed in keysetdump */ |
| 46 |
#include "java.h" |
| 47 |
#include "query.h" |
| 48 |
|
| 49 |
/*****************************************************************/ |
| 50 |
/****************** non graphic routines *********************/ |
| 51 |
/*****************************************************************/ |
| 52 |
|
| 53 |
/* we could compress on the fly in dump, |
| 54 |
but this is not longtetx specific |
| 55 |
|
| 56 |
FILE *pipe ; |
| 57 |
extern FILE* popen() ; |
| 58 |
a = arrayCreate(stackMark(s), char) ; |
| 59 |
cp = cp0 = arrayp(a,0,char) ; |
| 60 |
stackCursor(s,0) ; |
| 61 |
pipe = popen ("compress", "rw") ; |
| 62 |
if (pipe) |
| 63 |
{ register int i ; |
| 64 |
while (cp = stackNextText(s)) |
| 65 |
fprintf(pipe, "%s\n", cp) ; |
| 66 |
fprintf(pipe, "\n***LongTextEnd***\n") ; |
| 67 |
while((i = getc(pipe)) != EOF) |
| 68 |
*cp++ = i ; |
| 69 |
pclose(pipe) ; |
| 70 |
arrayMax(a) = cp - cp0 ; |
| 71 |
arrayStore(key, a,"c") ; |
| 72 |
stackDestroy(s) ; |
| 73 |
arrayDestroy(a) ; |
| 74 |
return TRUE ; |
| 75 |
} |
| 76 |
*/ |
| 77 |
|
| 78 |
BOOL longTextDump (ACEOUT dump_out, KEY k) |
| 79 |
/* DumpFuncType for class _VLongText */ |
| 80 |
{ |
| 81 |
char *cp ; |
| 82 |
Stack s = stackGet(k); |
| 83 |
|
| 84 |
if (s) |
| 85 |
{ |
| 86 |
stackCursor(s,0) ; |
| 87 |
while ((cp = stackNextText(s))) |
| 88 |
{ |
| 89 |
aceOutPrint (dump_out, "%s", cp) ; |
| 90 |
aceOutPrint (dump_out, "\n") ; |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
aceOutPrint (dump_out, "***LongTextEnd***\n") ; |
| 96 |
|
| 97 |
stackDestroy(s) ; |
| 98 |
|
| 99 |
return TRUE ; |
| 100 |
} /* longTextDump */ |
| 101 |
|
| 102 |
/************************************/ |
| 103 |
|
| 104 |
BOOL javaDumpLongText (ACEOUT dump_out, KEY key) |
| 105 |
{ |
| 106 |
char *cp; |
| 107 |
Stack s = stackGet(key); |
| 108 |
|
| 109 |
if (!s) |
| 110 |
return FALSE ; |
| 111 |
stackCursor(s,0) ; |
| 112 |
|
| 113 |
aceOutPrint (dump_out, "?LongText?%s?\t?txt?", |
| 114 |
freejavaprotect(name(key))); |
| 115 |
|
| 116 |
while ((cp = stackNextText(s)) ) |
| 117 |
{ |
| 118 |
aceOutPrint (dump_out, "%s", freejavaprotect(cp)); |
| 119 |
aceOutPrint (dump_out, "\\n"); |
| 120 |
} |
| 121 |
aceOutPrint (dump_out, "?\n\n"); |
| 122 |
|
| 123 |
stackDestroy (s) ; |
| 124 |
|
| 125 |
return TRUE ; |
| 126 |
} /* javaDumpLongText */ |
| 127 |
|
| 128 |
/************************************/ |
| 129 |
|
| 130 |
ParseFuncReturn longTextParse (ACEIN parse_io, KEY key, char **errtext) |
| 131 |
/* ParseFuncType */ |
| 132 |
{ |
| 133 |
char *cp = 0 ; |
| 134 |
Stack s = stackCreate(500) ; |
| 135 |
BOOL foundEnd = FALSE ; |
| 136 |
ParseFuncReturn result ; |
| 137 |
|
| 138 |
#ifdef ACEDB4 |
| 139 |
stackTextOnly(s); /* since we save it. */ |
| 140 |
#endif |
| 141 |
|
| 142 |
aceInSpecial (parse_io, "\n\\") ; |
| 143 |
while ((cp = aceInCard (parse_io))) |
| 144 |
if (strcmp(cp,"***LongTextEnd***") == 0) |
| 145 |
{ foundEnd = TRUE ; |
| 146 |
break ; |
| 147 |
} |
| 148 |
else |
| 149 |
pushText(s, cp) ; |
| 150 |
|
| 151 |
if (!foundEnd) |
| 152 |
{ messerror ("no ***LongTextEnd*** found when parsing LongText %s", |
| 153 |
name(key)) ; |
| 154 |
return PARSEFUNC_ERR ; |
| 155 |
} |
| 156 |
|
| 157 |
s->textOnly = TRUE ; |
| 158 |
if (stackMark(s)) |
| 159 |
{ |
| 160 |
stackStore(key,s) ; |
| 161 |
result = PARSEFUNC_OK ; |
| 162 |
} |
| 163 |
else |
| 164 |
{ |
| 165 |
/* srk - parsing an empty longtext object should |
| 166 |
* delete the associated object */ |
| 167 |
arrayKill(key); |
| 168 |
result = PARSEFUNC_EMPTY ; |
| 169 |
} |
| 170 |
stackDestroy(s) ; |
| 171 |
|
| 172 |
return result ; |
| 173 |
} /* longTextParse */ |
| 174 |
|
| 175 |
/************************************/ |
| 176 |
|
| 177 |
static BOOL longTextGrep (char *template, KEY key) |
| 178 |
{ |
| 179 |
char *cp = 0 ; |
| 180 |
Stack s ; |
| 181 |
static Stack s1 = 0 ; |
| 182 |
BOOL found = FALSE ; |
| 183 |
|
| 184 |
if (class(key) != _VLongText) |
| 185 |
return FALSE ; |
| 186 |
|
| 187 |
s = stackGet(key) ; |
| 188 |
if (!stackExists(s)) |
| 189 |
return FALSE ; |
| 190 |
|
| 191 |
s1 = stackReCreate(s1, stackMark(s)) ; |
| 192 |
|
| 193 |
stackCursor(s, 0) ; |
| 194 |
while ((cp = stackNextText(s))) |
| 195 |
{ catText(s1, cp) ; |
| 196 |
catText(s1, " ") ; |
| 197 |
} |
| 198 |
|
| 199 |
found = pickMatch(stackText(s1,0), template) ; |
| 200 |
|
| 201 |
stackDestroy(s) ; |
| 202 |
return found ; |
| 203 |
} |
| 204 |
|
| 205 |
/************************************/ |
| 206 |
|
| 207 |
KEYSET longGrep(char *template) |
| 208 |
{ KEY key = 0 , key1 ; |
| 209 |
KEYSET ks = keySetCreate() ; |
| 210 |
int n = 0 ; |
| 211 |
|
| 212 |
while(lexNext(_VLongText, &key)) |
| 213 |
{ if (longTextGrep(template, key)) |
| 214 |
{ if (!lexReClass(key, &key1, _VPaper)) |
| 215 |
key1 = key ; |
| 216 |
keySet(ks, n++) = key1 ; |
| 217 |
} |
| 218 |
} |
| 219 |
keySetSort (ks) ; /* needed because of ReClass calls */ |
| 220 |
keySetCompress(ks) ; |
| 221 |
return ks ; |
| 222 |
} |
| 223 |
|
| 224 |
/************************** eof **********************************/ |
| 225 |
|