/*************************************************************
wos2bib reads a Web of Science savedrecs.txt file and converts it to
  the BibTeX file format.

Copyright (C) 2003  Ethan Gutmann

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*************************************************************/
#include <stdio.h>
#include <string.h>
#include <ctype.h>

#define ARTICLE 0
#define FALSE 0
#define TRUE 1
#define HUGE_STR 32768
#define LARGE_STR 1024
#define SHORT_STR 32
#define substr(a,b,c,d) memmove(a,&b[c],d)
#define stripnewline(a) a[strlen(a)-1]='\0'

// define the bibliography structure.  This can be readily 
// extended as we encounter new types.  
typedef struct bibTeX_Rec{
  int pub_type;
  char key[LARGE_STR];
  char pub[LARGE_STR];
  char title[HUGE_STR];
  char author[HUGE_STR];
  char keywords[HUGE_STR];
  char abstract[HUGE_STR];
  char year[SHORT_STR];
  char month[SHORT_STR];
  char volume[SHORT_STR];
  char issue[SHORT_STR];
  char pages[SHORT_STR];
  struct bibRec *nextRec;
} bibRec;

// prototypes added by Maarten Sneep

void fixKeys(bibRec *curRecord);
void usage( void );
void writeRecord(FILE* unit, bibRec* curRecord);
void initRead(FILE* unit);
void GetNextRecord(FILE* unit, bibRec* curRecord);
void gotoEndofRec(FILE* unit);
void stringToLower( char *s );
void smartToLower(char *s);
void lowerAuthor(char* s);
void readMulti(FILE* unit, char* output, char* joiner, int toLower);
