HAI I HAVE ERROR IN RUNNING THIS PROGRAM I HAVE COPIED THE MAIN.H AND STRING .H. PLEASE GIVE THE SOLUTION AS SOON AS POSSIBLE

CODING

/* $Id: main.h,v 1.69 2005/01/18 06:19:46 prahl Exp $ */


#if defined(UNIX)
#define ENVSEP ':'
#define PATHSEP '/'
#endif


#if defined(MSDOS) || defined(OS2)
#define ENVSEP ';'
#define PATHSEP '\\'
#endif


#if defined(VMS)
#define ENVSEP ','
#define PATHSEP ''
#endif


#if defined(MAC_CLASSIC)
#define ENVSEP '^'
#define PATHSEP ':'
#include "MainMain.h"
#endif


#ifdef HAS_STRDUP
#else
#define strdup my_strdup
#endif


#ifndef SEEK_SET
#define SEEK_SET 0
#define SEEK_CUR 1
#endif


#define ERROR 0
#define WARNING 1


#define MAXCOMMANDLEN 100


/* available values for alignment */
#define LEFT      'l'
#define RIGHT      'r'
#define CENTERED  'c'
#define JUSTIFIED 'j'


#define PATHMAX 255


/*** error constants ***/
#include <assert.h>
#include <stdio.h>


/*** interpret comment lines that follow the '%' with this string ***/
extern const char  * InterpretCommentString;


typedef int        bool;


void            diagnostics(int level, char *format,...);


extern /* @dependent@ */ FILE *fRtf;    /* file pointer to RTF file */
extern            char *g_aux_name;
extern            char *g_toc_name;
extern            char *g_lof_name;
extern            char *g_lot_name;
extern            char *g_fff_name;
extern            char *g_bbl_name;
extern            char *g_home_dir;
extern            char *progname;            /* name of the executable file */


extern bool        GermanMode;
extern bool        FrenchMode;
extern bool        RussianMode;
extern bool        CzechMode;
extern bool        pagenumbering;
extern int        headings;


extern int        g_verbosity_level;
extern int        RecursionLevel;
extern int        g_left_margin_indent;
extern int        g_right_margin_indent;
extern char        alignment;


/* table  & tabbing variables */
extern char        *colFmt;
extern long        pos_begin_kill;
extern int        tabcounter;
extern int        colCount;
extern int        actCol;
extern int        g_equation_column;
extern int        tabcounter;


extern bool        twocolumn;
extern bool        titlepage;
extern bool        g_processing_equation;
extern bool        g_processing_preamble;
extern bool        g_processing_figure;
extern bool        g_processing_table;
extern bool        g_processing_tabbing;
extern bool        g_processing_tabular;
extern bool        g_processing_eqnarray;
extern int        g_processing_arrays;
extern int        g_processing_fields;
extern int        g_dots_per_inch;


extern int        g_document_type;
extern int        g_document_bibstyle;


extern bool        g_fields_use_EQ;
extern bool        g_fields_use_REF;


extern int        g_equation_number;
extern bool        g_escape_parent;
extern bool        g_show_equation_number;
extern int        g_enumerate_depth;
extern bool        g_suppress_equation_number;
extern bool        g_aux_file_missing;
extern bool        g_bbl_file_missing;
extern char        g_charset_encoding_name[20];
extern int        g_fcharset_number;
extern int      g_graphics_package;


extern char        *g_figure_label;
extern char        *g_table_label;
extern char        *g_equation_label;
extern char        *g_section_label;
extern char        *g_config_path;
extern char        *g_script_path;
extern char        g_field_separator;
extern char        *g_preamble;


extern double    g_png_equation_scale;
extern double    g_png_figure_scale;
extern bool        g_latex_figures;
extern bool        g_endfloat_figures;
extern bool        g_endfloat_tables;
extern bool        g_endfloat_markers;


extern bool        g_equation_inline_rtf;
extern bool        g_equation_display_rtf;
extern bool        g_equation_inline_bitmap;
extern bool        g_equation_display_bitmap;
extern bool        g_equation_comment;
extern bool        g_little_endian;
extern bool        g_tableofcontents;


void fprintRTF(char *format, ...);
void putRtfChar(char cThis);
char *getTmpPath(void);
char *my_strdup(const char *str);
FILE *my_fopen(char *path, char *mode);


void debug_malloc(void);



STRING.H CODING
----------------------



/***
*string.h - declarations for string manipulation functions
*
*       Copyright (c) Microsoft Corporation. All rights reserved.
*
*Purpose:
*       This file contains the function declarations for the string
*       manipulation functions.
*       [ANSI/System V]
*
*       [Public]
*
****/


#if     _MSC_VER > 1000
#pragma once
#endif


#ifndef _INC_STRING
#define _INC_STRING


#include <crtdefs.h>


#ifdef  __cplusplus
extern "C" {
#endif


#ifndef _NLSCMP_DEFINED
#define _NLSCMPERROR    2147483647  /* currently == INT_MAX */
#define _NLSCMP_DEFINED
#endif


/* Define NULL pointer value */
#ifndef NULL
#ifdef __cplusplus
#define NULL    0
#else
#define NULL    ((void *)0)
#endif
#endif


/* For backwards compatibility */
#define _WConst_return _CONST_RETURN


/* Function prototypes */
#ifndef _CRT_MEMORY_DEFINED
#define _CRT_MEMORY_DEFINED
_CRTIMP void *  __cdecl _memccpy( __out_bcount_opt(_MaxCount) void * _Dst, __in const void * _Src, __in int _Val, __in size_t _MaxCount);
_CRTIMP __checkReturn _CONST_RETURN void *  __cdecl memchr( __in_bcount_opt(_MaxCount) const void * _Buf , __in int _Val, __in size_t _MaxCount);
_CRTIMP __checkReturn int     __cdecl _memicmp(__in_bcount_opt(_Size) const void * _Buf1, __in_bcount_opt(_Size) const void * _Buf2, __in size_t _Size);
_CRTIMP __checkReturn int     __cdecl _memicmp_l(__in_bcount_opt(_Size) const void * _Buf1, __in_bcount_opt(_Size) const void * _Buf2, __in size_t _Size, __in_opt _locale_t _Locale);
__checkReturn int     __cdecl memcmp(__in_bcount_opt(_Size) const void * _Buf1, __in_bcount_opt(_Size) const void * _Buf2, __in size_t _Size);
_CRT_INSECURE_DEPRECATE_MEMORY(memcpy_s) void *  __cdecl memcpy(__out_bcount_full_opt(_Size) void * _Dst, __in_bcount_opt(_Size) const void * _Src, __in size_t _Size);
#if __STDC_WANT_SECURE_LIB__
_CRTIMP errno_t  __cdecl memcpy_s(__out_bcount_part_opt(_DstSize, _MaxCount) void * _Dst, __in rsize_t _DstSize, __in_bcount_opt(_MaxCount) const void * _Src, __in rsize_t _MaxCount);
#endif
void *  __cdecl memset(__out_bcount_full_opt(_Size) void * _Dst, __in int _Val, __in size_t _Size);


#if     !__STDC__
/* Non-ANSI names for compatibility */
_CRT_NONSTDC_DEPRECATE(_memccpy) _CRTIMP void * __cdecl memccpy(__out_bcount_opt(_Size) void * _Dst, __in_bcount_opt(_Size) const void * _Src, __in int _Val, __in size_t _Size);
_CRT_NONSTDC_DEPRECATE(_memicmp) _CRTIMP __checkReturn int __cdecl memicmp(__in_bcount_opt(_Size) const void * _Buf1, __in_bcount_opt(_Size) const void * _Buf2, __in size_t _Size);
#endif  /* __STDC__ */


#endif


_CRT_INSECURE_DEPRECATE(_strset_s) char *  __cdecl _strset(__inout_z char * _Str, __in int _Val);
_CRTIMP_ALTERNATIVE __checkReturn_wat errno_t __cdecl _strset_s(__inout_ecount_z(_DstSize) char * _Dst, __in size_t _DstSize, __in int _Value);
#if __STDC_WANT_SECURE_LIB__
_CRTIMP_ALTERNATIVE __checkReturn_wat errno_t __cdecl strcpy_s(__out_ecount_z(_DstSize) char * _Dst, __in rsize_t _DstSize, __in_z const char * _Src);
#endif
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(errno_t, strcpy_s, __out_ecount_z(_Size) char, _Dest, __in_z const char *, _Source)
__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1(char *, __RETURN_POLICY_DST, __EMPTY_DECLSPEC, strcpy, __out_z char, _Dest, __in_z const char *, _Source)
#if __STDC_WANT_SECURE_LIB__
_CRTIMP_ALTERNATIVE __checkReturn_wat errno_t __cdecl strcat_s(__inout_ecount_z(_DstSize) char * _Dst, __in rsize_t _DstSize, __in_z const char * _Src);
#endif
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(errno_t, strcat_s, __inout_ecount_z(_Size) char, _Dest, __in_z const char *, _Source)
__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1(char *, __RETURN_POLICY_DST, __EMPTY_DECLSPEC, strcat, __inout_z char, _Dest, __in_z const char *, _Source)
__checkReturn int     __cdecl strcmp(__in_z const char * _Str1, __in_z const char * _Str2);
__checkReturn size_t  __cdecl strlen(__in_z  const char * _Str);
_CRTIMP __checkReturn size_t  __cdecl strnlen(__in_ecount_z(_MaxCount)  const char * _Str, __in size_t _MaxCount);
#if __STDC_WANT_SECURE_LIB__ && !defined (__midl)
static __inline __checkReturn size_t  __CRTDECL strnlen_s(__in_ecount_z(_MaxCount)  const char * _Str, __in size_t _MaxCount)
{
return strnlen(_Str, _MaxCount);
}
#endif
#if __STDC_WANT_SECURE_LIB__
_CRTIMP __checkReturn_wat errno_t __cdecl memmove_s(__out_bcount_part_opt(_DstSize,_MaxCount) void * _Dst, __in rsize_t _DstSize, __in_bcount_opt(_MaxCount) const void * _Src, __in rsize_t _MaxCount);
#endif


#if     defined(_M_IA64)
_CRT_INSECURE_DEPRECATE_MEMORY(memmove_s) void *  __cdecl memmove(__out_bcount_full_opt(_Size) void * _Dst, __in_bcount_opt(_Size) const void * _Src, __in size_t _Size);
#else  /* defined (_M_IA64) */
_CRTIMP _CRT_INSECURE_DEPRECATE_MEMORY(memmove_s) void *  __cdecl memmove(__out_bcount_full_opt(_Size) void * _Dst, __in_bcount_opt(_Size) const void * _Src, __in size_t _Size);
#endif  /* defined (_M_IA64) */


#if defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC)
#pragma push_macro("_strdup")
#undef _strdup
#endif


_CRTIMP __checkReturn char *  __cdecl _strdup(__in_z_opt const char * _Src);


#if defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC)
#pragma pop_macro("_strdup")
#endif


_CRTIMP __checkReturn _CONST_RETURN char *  __cdecl strchr(__in_z const char * _Str, __in int _Val);
_CRTIMP __checkReturn int     __cdecl _stricmp(__in_z  const char * _Str1, __in_z  const char * _Str2);
_CRTIMP __checkReturn int     __cdecl _strcmpi(__in_z  const char * _Str1, __in_z  const char * _Str2);
_CRTIMP __checkReturn int     __cdecl _stricmp_l(__in_z  const char * _Str1, __in_z  const char * _Str2, __in_opt _locale_t _Locale);
_CRTIMP __checkReturn int     __cdecl strcoll(__in_z  const char * _Str1, __in_z  const  char * _Str2);
_CRTIMP __checkReturn int     __cdecl _strcoll_l(__in_z  const char * _Str1, __in_z  const char * _Str2, __in_opt _locale_t _Locale);
_CRTIMP __checkReturn int     __cdecl _stricoll(__in_z  const char * _Str1, __in_z  const char * _Str2);
_CRTIMP __checkReturn int     __cdecl _stricoll_l(__in_z  const char * _Str1, __in_z  const char * _Str2, __in_opt _locale_t _Locale);
_CRTIMP __checkReturn int     __cdecl _strncoll  (__in_z const char * _Str1, __in_z const char * _Str2, __in size_t _MaxCount);
_CRTIMP __checkReturn int     __cdecl _strncoll_l(__in_z const char * _Str1, __in_z const char * _Str2, __in size_t _MaxCount, __in_opt _locale_t _Locale);
_CRTIMP __checkReturn int     __cdecl _strnicoll (__in_z const char * _Str1, __in_z const char * _Str2, __in size_t _MaxCount);
_CRTIMP __checkReturn int     __cdecl _strnicoll_l(__in_z const char * _Str1, __in_z const char * _Str2, __in size_t _MaxCount, __in_opt _locale_t _Locale);
_CRTIMP __checkReturn size_t  __cdecl strcspn(__in_z  const char * _Str, __in_z  const char * _Control);
_CRT_INSECURE_DEPRECATE(_strerror_s) _CRTIMP __checkReturn char *  __cdecl _strerror(__in_z_opt const char * _ErrMsg);
_CRTIMP __checkReturn_wat errno_t __cdecl _strerror_s(__out_ecount_z(_SizeInBytes) char * _Buf, __in size_t _SizeInBytes, __in_z_opt const char * _ErrMsg);
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(errno_t, _strerror_s, __out_ecount(_Size) char, _Buffer, __in_z_opt const char *, _ErrorMessage)
_CRT_INSECURE_DEPRECATE(strerror_s) _CRTIMP __checkReturn char *  __cdecl strerror(__in int);
#if __STDC_WANT_SECURE_LIB__
_CRTIMP __checkReturn_wat errno_t __cdecl strerror_s(__out_ecount_z(_SizeInBytes) char * _Buf, __in size_t _SizeInBytes, __in int _ErrNum);
#endif
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(errno_t, strerror_s, __out_ecount(_Size) char, _Buffer, __in int, _ErrorMessage)
_CRTIMP __checkReturn_wat errno_t __cdecl _strlwr_s(__inout_ecount_z(_Size) char * _Str, __in size_t _Size);
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_0(errno_t, _strlwr_s, __inout_ecount_z(_Size) char, _String)
__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_0(char *, __RETURN_POLICY_DST, _CRTIMP, _strlwr, __inout_z char, _String)
_CRTIMP __checkReturn_wat errno_t __cdecl _strlwr_s_l(__inout_ecount_z(_Size) char * _Str, __in size_t _Size, __in_opt _locale_t _Locale);
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(errno_t, _strlwr_s_l, __inout_ecount_z(_Size) char, _String, __in_opt _locale_t, _Locale)
__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1_EX(char *, __RETURN_POLICY_DST, _CRTIMP, _strlwr_l, _strlwr_s_l, __inout_z char, _String, __in_opt _locale_t, _Locale)
#if __STDC_WANT_SECURE_LIB__
_CRTIMP_ALTERNATIVE __checkReturn_wat errno_t __cdecl strncat_s(__inout_ecount_z(_DstSize) char * _Dst, __in rsize_t _DstSize, __in_z const char * _Src, __in rsize_t _MaxCount);
#endif
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_2(errno_t, strncat_s, __inout_ecount_z(_Size) char, _Dest, __in_z const char *, _Source, __in size_t, _Count)
#pragma warning(push)
#pragma warning(disable:4609 6059)
/* prefast noise VSW 489802 */
__DEFINE_CPP_OVERLOAD_STANDARD_NFUNC_0_2_EX(char *, __RETURN_POLICY_DST, _CRTIMP, strncat, strncat_s, __inout_z char, __inout_ecount_z(_Count) char, _Dest, __in_z const char *, _Source, __in size_t, _Count)
#pragma warning(pop)
#if     defined(_M_IA64)
__checkReturn int     __cdecl strncmp(__in_z  const char * _Str1, __in_z const char * _Str2, __in size_t _MaxCount);
#else
_CRTIMP __checkReturn int     __cdecl strncmp(__in_z const char * _Str1, __in_z const char * _Str2, __in size_t _MaxCount);
#endif
_CRTIMP __checkReturn int     __cdecl _strnicmp(__in_z const char * _Str1, __in_z const char * _Str2, __in size_t _MaxCount);
_CRTIMP __checkReturn int     __cdecl _strnicmp_l(__in_z const char * _Str1, __in_z const char * _Str2, __in size_t _MaxCount, __in_opt _locale_t _Locale);
#if __STDC_WANT_SECURE_LIB__
_CRTIMP_ALTERNATIVE __checkReturn_wat errno_t __cdecl strncpy_s(__out_ecount_z(_DstSize) char * _Dst, __in rsize_t _DstSize, __in_z_opt const char * _Src, __in rsize_t _MaxCount);
#endif
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_2(errno_t, strncpy_s, __out_ecount(_Size) char, _Dest, __in_z const char *, _Source, __in size_t, _Count)
__DEFINE_CPP_OVERLOAD_STANDARD_NFUNC_0_2_EX(char *, __RETURN_POLICY_DST, _CRTIMP_NOIA64, strncpy, strncpy_s, __out_z char, __out_ecount(_Count) char, _Dest, __in_z const char *, _Source, __in size_t, _Count)
_CRT_INSECURE_DEPRECATE(_strnset_s) _CRTIMP char *  __cdecl _strnset(__inout_z char * _Str, __in int _Val, __in size_t _MaxCount);
_CRTIMP_ALTERNATIVE __checkReturn_wat errno_t __cdecl _strnset_s(__inout_ecount_z(_Size) char * _Str, __in size_t _Size, __in int _Val, __in size_t _MaxCount);
_CRTIMP __checkReturn _CONST_RETURN char *  __cdecl strpbrk(__in_z const char * _Str, __in_z const char * _Control);
_CRTIMP __checkReturn _CONST_RETURN char *  __cdecl strrchr(__in_z const char * _Str, __in int _Ch);
_CRTIMP char *  __cdecl _strrev(__inout_z char * _Str);
_CRTIMP __checkReturn size_t  __cdecl strspn(__in_z const char * _Str, __in_z const char * _Control);
_CRTIMP __checkReturn _CONST_RETURN char *  __cdecl strstr(__in_z const char * _Str, __in_z const char * _SubStr);
_CRT_INSECURE_DEPRECATE(strtok_s) _CRTIMP __checkReturn char *  __cdecl strtok(__inout_z_opt char * _Str, __in_z const char * _Delim);
#if __STDC_WANT_SECURE_LIB__
_CRTIMP_ALTERNATIVE __checkReturn char *  __cdecl strtok_s(__inout_z_opt char * _Str, __in_z const char * _Delim, __deref_inout_z_opt char ** _Context);
#endif
_CRTIMP __checkReturn_wat errno_t __cdecl _strupr_s(__inout_ecount_z(_Size) char * _Str, __in size_t _Size);
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_0(errno_t, _strupr_s, __inout_ecount_z(_Size) char, _String)
__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_0(char *, __RETURN_POLICY_DST, _CRTIMP, _strupr, __inout_z char, _String)
_CRTIMP __checkReturn_wat errno_t __cdecl _strupr_s_l(__inout_ecount_z(_Size) char * _Str, __in size_t _Size, _locale_t _Locale);
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(errno_t, _strupr_s_l, __inout_ecount_z(_Size) char, _String, _locale_t, _Locale)
__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1_EX(char *, __RETURN_POLICY_DST, _CRTIMP, _strupr_l, _strupr_s_l, __inout_z char, _String, __in_opt _locale_t, _Locale)
_CRTIMP __checkReturn_opt size_t  __cdecl strxfrm (__out_z_opt char * _Dst, __in_z const char * _Src, __in size_t _MaxCount);
_CRTIMP __checkReturn_opt size_t  __cdecl _strxfrm_l(__out_z_opt char * _Dst, __in_z const char * _Src, __in size_t _MaxCount, __in_opt _locale_t _Locale);


#ifdef __cplusplus
extern "C++" {
#ifndef _CPP_NARROW_INLINES_DEFINED
#define _CPP_NARROW_INLINES_DEFINED
inline __checkReturn char * __CRTDECL strchr(__in_z char * _Str, __in int _Ch)
{ return (char*)strchr((const char*)_Str, _Ch); }
inline __checkReturn char * __CRTDECL strpbrk(__in_z char * _Str, __in_z const char * _Control)
{ return (char*)strpbrk((const char*)_Str, _Control); }
inline __checkReturn char * __CRTDECL strrchr(__in_z char * _Str, __in int _Ch)
{ return (char*)strrchr((const char*)_Str, _Ch); }
inline __checkReturn char * __CRTDECL strstr(__in_z char * _Str, __in_z const char * _SubStr)
{ return (char*)strstr((const char*)_Str, _SubStr); }
#endif
#ifndef _CPP_MEMCHR_DEFINED
#define _CPP_MEMCHR_DEFINED
inline __checkReturn void * __CRTDECL memchr(__in_bcount_opt(_N) void * _Pv, __in int _C, __in size_t _N)
{ return (void*)memchr((const void*)_Pv, _C, _N); }
#endif
}
#endif


#if     !__STDC__


#if defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC)
#pragma push_macro("strdup")
#undef strdup
#endif


_CRT_NONSTDC_DEPRECATE(_strdup) _CRTIMP __checkReturn char * __cdecl strdup(__in_z_opt const char * _Src);
#if defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC)
#pragma pop_macro("strdup")
#endif


/* prototypes for oldnames.lib functions */
_CRT_NONSTDC_DEPRECATE(_strcmpi) _CRTIMP __checkReturn int __cdecl strcmpi(__in_z const char * _Str1, __in_z const char * _Str2);
_CRT_NONSTDC_DEPRECATE(_stricmp) _CRTIMP __checkReturn int __cdecl stricmp(__in_z const char * _Str1, __in_z const char * _Str2);
_CRT_NONSTDC_DEPRECATE(_strlwr) _CRTIMP char * __cdecl strlwr(__inout_z char * _Str);
_CRT_NONSTDC_DEPRECATE(_strnicmp) _CRTIMP __checkReturn int __cdecl strnicmp(__in_z const char * _Str1, __in_z const char * _Str, __in size_t _MaxCount);
_CRT_NONSTDC_DEPRECATE(_strnset) _CRTIMP char * __cdecl strnset(__inout_z char * _Str, __in int _Val, __in size_t _MaxCount);
_CRT_NONSTDC_DEPRECATE(_strrev) _CRTIMP char * __cdecl strrev(__inout_z char * _Str);
_CRT_NONSTDC_DEPRECATE(_strset)         char * __cdecl strset(__inout_z char * _Str, __in int _Val);
_CRT_NONSTDC_DEPRECATE(_strupr) _CRTIMP char * __cdecl strupr(__inout_z char * _Str);


#endif  /* !__STDC__ */



#ifndef _WSTRING_DEFINED


/* wide function prototypes, also declared in wchar.h  */


#if defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC)
#pragma push_macro("_wcsdup")
#undef _wcsdup
#endif


_CRTIMP __checkReturn wchar_t * __cdecl _wcsdup(__in_z const wchar_t * _Str);


#if defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC)
#pragma pop_macro("_wcsdup")
#endif


#if __STDC_WANT_SECURE_LIB__
_CRTIMP_ALTERNATIVE __checkReturn_wat errno_t __cdecl wcscat_s(__inout_ecount_z(_DstSize) wchar_t * _Dst, __in rsize_t _DstSize, const wchar_t * _Src);
#endif
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(errno_t, wcscat_s, __inout_ecount_z(_Size) wchar_t, _Dest, __in_z const wchar_t *, _Source)
__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1(wchar_t *, __RETURN_POLICY_DST, _CRTIMP, wcscat, __inout_z wchar_t, _Dest, __in_z const wchar_t *, _Source)
_CRTIMP __checkReturn _CONST_RETURN wchar_t * __cdecl wcschr(__in_z const wchar_t * _Str, wchar_t _Ch);
_CRTIMP __checkReturn int __cdecl wcscmp(__in_z const wchar_t * _Str1, __in_z const wchar_t * _Str2);
#if __STDC_WANT_SECURE_LIB__
_CRTIMP_ALTERNATIVE __checkReturn_wat errno_t __cdecl wcscpy_s(__out_ecount_z(_DstSize) wchar_t * _Dst, __in rsize_t _DstSize, __in_z const wchar_t * _Src);
#endif
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(errno_t, wcscpy_s, __out_ecount(_Size) wchar_t, _Dest, __in_z const wchar_t *, _Source)
__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1(wchar_t *, __RETURN_POLICY_DST, _CRTIMP, wcscpy, __out_z wchar_t, _Dest, __in_z const wchar_t *, _Source)
_CRTIMP __checkReturn size_t __cdecl wcscspn(__in_z const wchar_t * _Str, __in_z const wchar_t * _Control);
_CRTIMP __checkReturn size_t __cdecl wcslen(__in_z const wchar_t * _Str);
_CRTIMP __checkReturn size_t __cdecl wcsnlen(__in_ecount_z(_MaxCount) const wchar_t * _Src, __in size_t _MaxCount);
#if __STDC_WANT_SECURE_LIB__ && !defined (__midl)
static __inline __checkReturn size_t __CRTDECL wcsnlen_s(__in_ecount_z(_MaxCount) const wchar_t * _Src, __in size_t _MaxCount)
{
return wcsnlen(_Src, _MaxCount);
}
#endif
#if __STDC_WANT_SECURE_LIB__
_CRTIMP_ALTERNATIVE __checkReturn_wat errno_t __cdecl wcsncat_s(__inout_ecount_z(_DstSize) wchar_t * _Dst, __in rsize_t _DstSize, __in_z const wchar_t * _Src, __in rsize_t _MaxCount);
#endif
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_2(errno_t, wcsncat_s, __inout_ecount_z(_Size) wchar_t, _Dest, __in_z const wchar_t *, _Source, __in size_t, _Count)
__DEFINE_CPP_OVERLOAD_STANDARD_NFUNC_0_2_EX(wchar_t *, __RETURN_POLICY_DST, _CRTIMP, wcsncat, wcsncat_s, __inout_ecount_z(_Count) wchar_t, __inout wchar_t, _Dest, __in_z const wchar_t *, _Source, __in size_t, _Count)
_CRTIMP __checkReturn int __cdecl wcsncmp(__in_z const wchar_t * _Str1, __in_z const wchar_t * _Str2, __in size_t _MaxCount);
#if __STDC_WANT_SECURE_LIB__
_CRTIMP_ALTERNATIVE __checkReturn_wat errno_t __cdecl wcsncpy_s(__out_ecount_z(_DstSize) wchar_t * _Dst, __in rsize_t _DstSize, __in_z const wchar_t * _Src, __in rsize_t _MaxCount);
#endif
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_2(errno_t, wcsncpy_s, __out_ecount(_Size) wchar_t, _Dest, __in_z const wchar_t *, _Source, __in size_t, _Count)
__DEFINE_CPP_OVERLOAD_STANDARD_NFUNC_0_2_EX(wchar_t *, __RETURN_POLICY_DST, _CRTIMP, wcsncpy, wcsncpy_s, __out_z wchar_t, __out_ecount(_Count) wchar_t, _Dest, __in_z const wchar_t *, _Source, __in size_t, _Count)
_CRTIMP __checkReturn _CONST_RETURN wchar_t * __cdecl wcspbrk(__in_z const wchar_t * _Str, __in_z const wchar_t * _Control);
_CRTIMP __checkReturn _CONST_RETURN wchar_t * __cdecl wcsrchr(__in_z const wchar_t * _Str, __in wchar_t _Ch);
_CRTIMP __checkReturn size_t __cdecl wcsspn(__in_z const wchar_t * _Str, __in_z const wchar_t * _Control);
_CRTIMP __checkReturn _CONST_RETURN wchar_t * __cdecl wcsstr(__in_z const wchar_t * _Str, __in_z const wchar_t * _SubStr);
_CRT_INSECURE_DEPRECATE(wcstok_s) _CRTIMP __checkReturn wchar_t * __cdecl wcstok(__inout_z_opt wchar_t * _Str, __in_z const wchar_t * _Delim);
_CRTIMP_ALTERNATIVE __checkReturn wchar_t * __cdecl wcstok_s(__inout_z_opt wchar_t * _Str, __in_z const wchar_t * _Delim, __deref_inout_z_opt wchar_t ** _Context);
_CRT_INSECURE_DEPRECATE(_wcserror_s) _CRTIMP __checkReturn wchar_t * __cdecl _wcserror(__in int _ErrNum);
_CRTIMP __checkReturn_wat errno_t __cdecl _wcserror_s(__out_ecount_z_opt(_SizeInWords) wchar_t * _Buf, __in size_t _SizeInWords, __in int _ErrNum);
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(errno_t, _wcserror_s, __out_ecount(_Size) wchar_t, _Buffer, __in int, _Error)
_CRT_INSECURE_DEPRECATE(__wcserror_s) _CRTIMP __checkReturn wchar_t * __cdecl __wcserror(__in_z_opt const wchar_t * _Str);
_CRTIMP __checkReturn_wat errno_t __cdecl __wcserror_s(__out_ecount_z_opt(_SizeInWords) wchar_t * _Buffer, __in size_t _SizeInWords, __in_z const wchar_t * _ErrMsg);
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(errno_t, __wcserror_s, __out_ecount(_Size) wchar_t, _Buffer, __in_z const wchar_t *, _ErrorMessage)


_CRTIMP __checkReturn int __cdecl _wcsicmp(__in_z const wchar_t * _Str1, __in_z const wchar_t * _Str2);
_CRTIMP __checkReturn int __cdecl _wcsicmp_l(__in_z const wchar_t * _Str1, __in_z const wchar_t * _Str2, __in_opt _locale_t _Locale);
_CRTIMP __checkReturn int __cdecl _wcsnicmp(__in_z const wchar_t * _Str1, __in_z const wchar_t * _Str2, __in size_t _MaxCount);
_CRTIMP __checkReturn int __cdecl _wcsnicmp_l(__in_z const wchar_t * _Str1, __in_z const wchar_t * _Str2, __in size_t _MaxCount, __in_opt _locale_t _Locale);
_CRT_INSECURE_DEPRECATE(_wcsnset_s) _CRTIMP wchar_t * __cdecl _wcsnset(__inout_z wchar_t * _Str, __in_z wchar_t _Val, __in size_t _MaxCount);
_CRTIMP_ALTERNATIVE __checkReturn_wat errno_t __cdecl _wcsnset_s(__inout_ecount_z(_DstSizeInWords) wchar_t * _Dst, __in size_t _DstSizeInWords, wchar_t _Val, __in size_t _MaxCount);
_CRTIMP wchar_t * __cdecl _wcsrev(__inout_z wchar_t * _Str);
_CRT_INSECURE_DEPRECATE(_wcsset_s) _CRTIMP wchar_t * __cdecl _wcsset(__inout_z wchar_t * _Str, wchar_t _Val);
_CRTIMP_ALTERNATIVE __checkReturn_wat errno_t __cdecl _wcsset_s(__inout_ecount_z(_SizeInWords) wchar_t * _Str, __in size_t _SizeInWords, wchar_t _Val);


_CRTIMP __checkReturn_wat errno_t __cdecl _wcslwr_s(__inout_ecount_z(_SizeInWords) wchar_t * _Str, __in size_t _SizeInWords);
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_0(errno_t, _wcslwr_s, __inout_ecount_z(_Size) wchar_t, _String)
__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_0(wchar_t *, __RETURN_POLICY_DST, _CRTIMP, _wcslwr, __inout_z wchar_t, _String)
_CRTIMP __checkReturn_wat errno_t __cdecl _wcslwr_s_l(__inout_ecount_z(_SizeInWords) wchar_t * _Str, __in size_t _SizeInWords, __in_opt _locale_t _Locale);
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(errno_t, _wcslwr_s_l, __inout_ecount_z(_Size) wchar_t, _String, __in_opt _locale_t, _Locale)
__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1_EX(wchar_t *, __RETURN_POLICY_DST, _CRTIMP, _wcslwr_l, _wcslwr_s_l, __inout_z wchar_t, _String, __in_opt _locale_t, _Locale)
_CRTIMP __checkReturn_wat errno_t __cdecl _wcsupr_s(__inout_ecount_z(_Size) wchar_t * _Str, __in size_t _Size);
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_0(errno_t, _wcsupr_s, __inout_ecount_z(_Size) wchar_t, _String)
__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_0(wchar_t *, __RETURN_POLICY_DST, _CRTIMP, _wcsupr, __inout_z wchar_t, _String)
_CRTIMP __checkReturn_wat errno_t __cdecl _wcsupr_s_l(__inout_ecount_z(_Size) wchar_t * _Str, __in size_t _Size, __in_opt _locale_t _Locale);
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(errno_t, _wcsupr_s_l, __inout_ecount_z(_size) wchar_t, _String, __in_opt _locale_t, _Locale)
__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1_EX(wchar_t *, __RETURN_POLICY_DST, _CRTIMP, _wcsupr_l, _wcsupr_s_l, __inout_z wchar_t, _String, __in_opt _locale_t, _Locale)
_CRTIMP __checkReturn_opt size_t __cdecl wcsxfrm(__out_z_opt wchar_t * _Dst, __in_z const wchar_t * _Src, __in size_t _MaxCount);
_CRTIMP __checkReturn_opt size_t __cdecl _wcsxfrm_l(__out_z_opt wchar_t * _Dst, __in_z const wchar_t *_Src, __in size_t _MaxCount, __in_opt _locale_t _Locale);
_CRTIMP __checkReturn int __cdecl wcscoll(__in_z const wchar_t * _Str1, __in_z const wchar_t * _Str2);
_CRTIMP __checkReturn int __cdecl _wcscoll_l(__in_z const wchar_t * _Str1, __in_z const wchar_t * _Str2, __in_opt _locale_t _Locale);
_CRTIMP __checkReturn int __cdecl _wcsicoll(__in_z const wchar_t * _Str1, __in_z const wchar_t * _Str2);
_CRTIMP __checkReturn int __cdecl _wcsicoll_l(__in_z const wchar_t * _Str1, __in_z const wchar_t *_Str2, __in_opt _locale_t _Locale);
_CRTIMP __checkReturn int __cdecl _wcsncoll(__in_z const wchar_t * _Str1, __in_z const wchar_t * _Str2, __in size_t _MaxCount);
_CRTIMP __checkReturn int __cdecl _wcsncoll_l(__in_z const wchar_t * _Str1, __in_z const wchar_t * _Str2, __in size_t _MaxCount, __in_opt _locale_t _Locale);
_CRTIMP __checkReturn int __cdecl _wcsnicoll(__in_z const wchar_t * _Str1, __in_z const wchar_t * _Str2, __in size_t _MaxCount);
_CRTIMP __checkReturn int __cdecl _wcsnicoll_l(__in_z const wchar_t * _Str1, __in_z const wchar_t * _Str2, __in size_t _MaxCount, __in_opt _locale_t _Locale);


#ifdef  __cplusplus
#ifndef _CPP_WIDE_INLINES_DEFINED
#define _CPP_WIDE_INLINES_DEFINED
extern "C++" {
inline __checkReturn wchar_t * __CRTDECL wcschr(__in_z wchar_t *_Str, wchar_t _Ch)
{return ((wchar_t *)wcschr((const wchar_t *)_Str, _Ch)); }
inline __checkReturn wchar_t * __CRTDECL wcspbrk(__in_z wchar_t *_Str, __in_z const wchar_t *_Control)
{return ((wchar_t *)wcspbrk((const wchar_t *)_Str, _Control)); }
inline __checkReturn wchar_t * __CRTDECL wcsrchr(__in_z wchar_t *_Str, __in wchar_t _Ch)
{return ((wchar_t *)wcsrchr((const wchar_t *)_Str, _Ch)); }
inline __checkReturn wchar_t * __CRTDECL wcsstr(__in_z wchar_t *_Str, __in_z const wchar_t *_SubStr)
{return ((wchar_t *)wcsstr((const wchar_t *)_Str, _SubStr)); }
}
#endif
#endif


#if     !__STDC__


#if defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC)
#pragma push_macro("wcsdup")
#undef wcsdup
#endif


_CRT_NONSTDC_DEPRECATE(_wcsdup) _CRTIMP __checkReturn wchar_t * __cdecl wcsdup(__in_z const wchar_t * _Str);


#if defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC)
#pragma pop_macro("wcsdup")
#endif


/* old names */
#define wcswcs wcsstr


/* prototypes for oldnames.lib functions */
_CRT_NONSTDC_DEPRECATE(_wcsicmp) _CRTIMP __checkReturn int __cdecl wcsicmp(__in_z const wchar_t * _Str1, __in_z const wchar_t * _Str2);
_CRT_NONSTDC_DEPRECATE(_wcsnicmp) _CRTIMP __checkReturn int __cdecl wcsnicmp(__in_z const wchar_t * _Str1, __in_z const wchar_t * _Str2, __in size_t _MaxCount);
_CRT_NONSTDC_DEPRECATE(_wcsnset) _CRTIMP wchar_t * __cdecl wcsnset(__inout_z wchar_t * _Str, __in_z wchar_t _Val, __in size_t _MaxCount);
_CRT_NONSTDC_DEPRECATE(_wcsrev) _CRTIMP wchar_t * __cdecl wcsrev(__inout_z wchar_t * _Str);
_CRT_NONSTDC_DEPRECATE(_wcsset) _CRTIMP wchar_t * __cdecl wcsset(__inout_z wchar_t * _Str, wchar_t _Val);
_CRT_NONSTDC_DEPRECATE(_wcslwr) _CRTIMP wchar_t * __cdecl wcslwr(__inout_z wchar_t * _Str);
_CRT_NONSTDC_DEPRECATE(_wcsupr) _CRTIMP wchar_t * __cdecl wcsupr(__inout_z wchar_t * _Str);
_CRT_NONSTDC_DEPRECATE(_wcsicoll) _CRTIMP __checkReturn int __cdecl wcsicoll(__in_z const wchar_t * _Str1, __in_z const wchar_t * _Str2);


#endif  /* !__STDC__ */


#define _WSTRING_DEFINED
#endif



#ifdef  __cplusplus
}
#endif


#endif  /* _INC_STRING */

Error:

1>------ Build started: Project: vc, Configuration: Debug Win32 ------
1>Compiling...
1>mygetopt.c
1>c:\program files\microsoft visual studio 8\vc\include\string.h(205) : error C2375: 'my_strdup' : redefinition; different linkage
1>        c:\l2r\include\main.h(147) : see declaration of 'my_strdup'
1>vc - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped

Edited 3 Years Ago by happygeek: fixed formatting

why did you post string.h? that is a standard header file that is supplied by your compiler and you should not be changing it nor making a copy of it and adding it to your project.

The problem is probably in mygetopt.c which you did not post.

why did you post string.h? that is a standard header file that is supplied by your compiler and you should not be changing it nor making a copy of it and adding it to your project.

The problem is probably in mygetopt.c which you did not post.

I HAVE POSTED MYGETOPT.C PLEASE GIVE THE SOLUTION AS SOON AS POSSIBLE

/*
 * my_getopt  is supposed to emulate the C Library getopt (which, according
 * to the man pages, is written by Henry Spencer to emulate the Bell Lab
 * version).
 * 
 * my_getopt is scanning argv[optind] (and, perhaps, following arguments),
 * looking for the first option starting with `-' and a character from
 * optstring[]. Therefore, if you are looking for options in argv[1] etc.,
 * you should initialize optind with 1 (not 0, as the manual erroneously
 * claims).
 * 
 * Experiments with getopt() established that when an argument consists of more
 * than one option, getopt() stores the pointer to the beginning of the
 * argument as a static variable, for re-use later.
 * 
 * See the getopt manual pages for more information on getopt.
 * 
 * Written by V.Menkov, IU, 1995
 */

#include "main.h"
#include <stdlib.h>
#include <string.h>
#include "mygetopt.h"

char *optarg = 0;
int optind = 1;

int my_getopt(int argc, char **argv, char *optstring)
{
    char *q;
    static char *rem = NULL;
    int c;
    int needarg = 0;

    optarg = NULL;

    diagnostics(4, "Processing option `%s'", argv[optind]);

    /* 
     * printf("optind = %d\n", optind);  if (rem) printf("rem=`%s'\n",
     * rem);
     */

    if (!rem) {
        if (optind < argc && argv[optind][0] == '-') {
            rem = argv[optind] + 1;
            if (*rem == 0)
                return EOF;     /* Treat lone "-" as a non-option arg */
            if (*rem == '-') {
                optind++;
                return EOF;
            }                   /* skip "--" and terminate */
        } else
            return EOF;
    }
    c = *rem;
    q = strchr(optstring, c);
    if (q && c != ':') {        /* matched */
        needarg = (q[1] == ':');
        if (needarg) {
            if (rem[1] != 0)
                optarg = rem + 1;
            else {
                optind++;
                if (optind < argc)
                    optarg = argv[optind];
                else {
                    fprintf(stderr, "Missing argument after -%c\n", c);
                    exit(1);
                }
            }
        } else
            rem++;
    } else {
        fprintf(stderr, "%s: illegal option -- %c\n", argv[0], c);
        c = '?';
        rem++;
    }
    if (needarg || *rem == 0) {
        rem = NULL;
        optind++;
    }
    return c;
}

Error:
=====
1>------ Build started: Project: vc, Configuration: Debug Win32 ------
1>Compiling...
1>mygetopt.c
1>c:\program files\microsoft visual studio 8\vc\include\string.h(205) : error C2375: 'my_strdup' : redefinition; different linkage
1> c:\l2r\include\main.h(147) : see declaration of 'my_strdup'
1>vc - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped

THANKS FOR YOUR VALUABLE REPLY
ARUN PRABHAKAR

I just compiled it with VC++ 2005 Express and did not get any of those errors. I commented out line 24 because I don't have mygetopt.h and line 38 because I don't have diagnostics(). I added main() and everything else compiled and linked ok. Maybe there is a problem with mygetopt.h ????

I AM CONVERTING LATEX TO RTF FORMAT. WHILE COMPILING THESE FILES SOME ERROR THROWS, WHICH I HAVE MENTIONED BELOW. PLEASE GIVE A SOLUTION. I HAVE DOWNLOADED THESE FILES FROM THE FOLLOWING LINK:
This file is available from

THESE ARE THE FOLLOWING SAMPLE FILES .

MYGETOPT.H

int             my_getopt(int argc, char **argv, char *optstring);

MYGETOPT.C

/*
* my_getopt  is supposed to emulate the C Library getopt (which, according
* to the man pages, is written by Henry Spencer to emulate the Bell Lab
* version).
*
* my_getopt is scanning argv[optind] (and, perhaps, following arguments),
* looking for the first option starting with `-' and a character from
* optstring[]. Therefore, if you are looking for options in argv[1] etc.,
* you should initialize optind with 1 (not 0, as the manual erroneously
* claims).
*
* Experiments with getopt() established that when an argument consists of more
* than one option, getopt() stores the pointer to the beginning of the
* argument as a static variable, for re-use later.
*
* See the getopt manual pages for more information on getopt.
*
* Written by V.Menkov, IU, 1995
*/


#include "main.h"
#include <stdlib.h>
#include <string.h>
#include "mygetopt.h"


char *optarg = 0;
int optind = 1;


int my_getopt(int argc, char **argv, char *optstring)
{
char *q;
static char *rem = NULL;
int c;
int needarg = 0;


optarg = NULL;


diagnostics(4, "Processing option `%s'", argv[optind]);


/*
* printf("optind = %d\n", optind);  if (rem) printf("rem=`%s'\n",
* rem);
*/


if (!rem) {
if (optind < argc && argv[optind][0] == '-') {
rem = argv[optind] + 1;
if (*rem == 0)
return EOF;     /* Treat lone "-" as a non-option arg */
if (*rem == '-') {
optind++;
return EOF;
}                   /* skip "--" and terminate */
} else
return EOF;
}
c = *rem;
q = strchr(optstring, c);
if (q && c != ':') {        /* matched */
needarg = (q[1] == ':');
if (needarg) {
if (rem[1] != 0)
optarg = rem + 1;
else {
optind++;
if (optind < argc)
optarg = argv[optind];
else {
fprintf(stderr, "Missing argument after -%c\n", c);
exit(1);
}
}
} else
rem++;
} else {
fprintf(stderr, "%s: illegal option -- %c\n", argv[0], c);
c = '?';
rem++;
}
if (needarg || *rem == 0) {
rem = NULL;
optind++;
}
return c;
}

MAIN.C

/* main.c - LaTeX to RTF conversion program


Copyright (C) 1995-2002 The Free Software Foundation


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.


This file is available from http://sourceforge.net/projects/latex2rtf/


Authors:
1995 Fernando Dorner, Andreas Granzer, Freidrich Polzer, Gerhard Trisko
1995-1997 Ralf Schlatterbeck
1998-2000 Georg Lehner
2001-2002 Scott Prahl
*/
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <errno.h>
#include "main.h"
#include "mygetopt.h"
#include "convert.h"
#include "commands.h"
#include "chars.h"
#include "fonts.h"
#include "stack.h"
#include "direct.h"
#include "ignore.h"
#include "version.h"
#include "funct1.h"
#include "cfg.h"
#include "encode.h"
#include "util.h"
#include "parser.h"
#include "lengths.h"
#include "counters.h"
#include "preamble.h"
#include "xref.h"


FILE *fRtf = NULL;              /* file pointer to RTF file */
char *g_tex_name = NULL;
char *g_rtf_name = NULL;
char *g_aux_name = NULL;
char *g_toc_name = NULL;
char *g_lof_name = NULL;
char *g_lot_name = NULL;
char *g_fff_name = NULL;
char *g_ttt_name = NULL;
char *g_bbl_name = NULL;
char *g_home_dir = NULL;


/*** interpret comment lines that follow the '%' with this string ***/
const char *InterpretCommentString = "latex2rtf:";


char *progname;                 /* name of the executable file */
bool GermanMode = FALSE;        /* support germanstyle */
bool FrenchMode = FALSE;        /* support frenchstyle */
bool RussianMode = FALSE;       /* support russianstyle */
bool CzechMode = FALSE;         /* support czech */


char g_charset_encoding_name[20] = "cp1252";
int g_fcharset_number = 0;


bool twoside = FALSE;
int g_verbosity_level = WARNING;
bool g_little_endian = FALSE;   /* set properly in main() */
int g_dots_per_inch = 300;


bool pagenumbering = TRUE;      /* by default use plain style */
int headings = FALSE;


bool g_processing_preamble = TRUE;  /* flag set until \begin{document} */
bool g_processing_figure = FALSE;   /* flag, set for figures and not tables */
bool g_processing_eqnarray = FALSE; /* flag set when in an eqnarry */
int g_processing_arrays = 0;
int g_processing_fields = 0;


bool g_show_equation_number = FALSE;
int g_enumerate_depth = 0;
bool g_suppress_equation_number = FALSE;
bool g_aux_file_missing = FALSE;    /* assume that it exists */
bool g_bbl_file_missing = FALSE;    /* assume that it exists */


bool g_document_type = FORMAT_ARTICLE;
int g_document_bibstyle = BIBSTYLE_STANDARD;


bool g_fields_use_EQ = TRUE;
bool g_fields_use_REF = TRUE;


int g_safety_braces = 0;
bool g_processing_equation = FALSE;
bool g_RTF_warnings = FALSE;
char *g_config_path = NULL;
char *g_script_path = NULL;
char *g_tmp_path = NULL;
char *g_preamble = NULL;
char g_field_separator = ',';
bool g_escape_parent = TRUE;


bool g_equation_display_rtf = TRUE;
bool g_equation_inline_rtf = TRUE;
bool g_equation_inline_bitmap = FALSE;
bool g_equation_display_bitmap = FALSE;
bool g_equation_comment = FALSE;
bool g_tableofcontents = FALSE;


double g_png_equation_scale = 1.22;
double g_png_figure_scale = 1.35;
bool g_latex_figures = FALSE;
bool g_endfloat_figures = FALSE;
bool g_endfloat_tables = FALSE;
bool g_endfloat_markers = TRUE;
int  g_graphics_package = GRAPHICS_NONE;


int indent = 0;
char alignment = JUSTIFIED;     /* default for justified: */


int RecursionLevel = 0;
bool twocolumn = FALSE;
bool titlepage = FALSE;
char PATHSEP;


static void OpenRtfFile(char *filename, FILE ** f);
static void CloseRtf(FILE ** f);
static void ConvertLatexPreamble(void);
static void InitializeLatexLengths(void);


static void SetEndianness(void);
static void ConvertWholeDocument(void);
static void print_usage(void);
static void print_version(void);


extern char *optarg;
extern int optind;


int main(int argc, char **argv)
{
int c, x;
char *p;
char *basename = NULL;
double xx;


SetEndianness();
progname = argv[0];


InitializeStack();
InitializeLatexLengths();
InitializeBibliography();


while ((c = my_getopt(argc, argv, "lhpvFSWZ:o:a:b:d:f:i:s:C:D:M:P:T:")) != EOF) {
switch (c) {
case 'a':
g_aux_name = optarg;
break;
case 'b':
g_bbl_name = optarg;
break;
case 'd':
g_verbosity_level = *optarg - '0';
if (g_verbosity_level < 0 || g_verbosity_level > 7) {
diagnostics(WARNING, "debug level (-d# option) must be 0-7");
print_usage();
}
break;
case 'f':
sscanf(optarg, "%d", &x);
diagnostics(2, "Field option = %s x=%d", optarg, x);
g_fields_use_EQ = (x & 1) ? TRUE : FALSE;
g_fields_use_REF = (x & 2) ? TRUE : FALSE;
break;
case 'i':
setPackageBabel(optarg);
break;
case 'l':
setPackageBabel("latin1");
break;
case 'o':
g_rtf_name = strdup(optarg);
break;
case 'p':
g_escape_parent = FALSE;
break;
case 'v':
print_version();
return (0);
case 'C':
setPackageInputenc(optarg);
break;
case 'D':
sscanf(optarg, "%d", &g_dots_per_inch);
if (g_dots_per_inch < 25 || g_dots_per_inch > 600)
fprintf(stderr, "Dots per inch must be between 25 and 600 dpi\n");
break;
case 'F':
g_latex_figures = TRUE;
break;
case 'M':
sscanf(optarg, "%d", &x);
diagnostics(2, "Math option = %s x=%d", optarg, x);
g_equation_display_rtf = (x & 1) ? TRUE : FALSE;
g_equation_inline_rtf = (x & 2) ? TRUE : FALSE;
g_equation_display_bitmap = (x & 4) ? TRUE : FALSE;
g_equation_inline_bitmap = (x & 8) ? TRUE : FALSE;
g_equation_comment = (x & 16) ? TRUE : FALSE;
diagnostics(2, "Math option g_equation_display_rtf      = %d", g_equation_display_rtf);
diagnostics(2, "Math option g_equation_inline_rtf          = %d", g_equation_inline_rtf);
diagnostics(2, "Math option g_equation_display_bitmap   = %d", g_equation_display_bitmap);
diagnostics(2, "Math option g_equation_inline_bitmap    = %d", g_equation_inline_bitmap);
diagnostics(2, "Math option g_equation_comment          = %d", g_equation_comment);
if (!g_equation_comment && !g_equation_inline_rtf && !g_equation_inline_bitmap)
g_equation_inline_rtf = TRUE;
if (!g_equation_comment && !g_equation_display_rtf && !g_equation_display_bitmap)
g_equation_display_rtf = TRUE;
break;


case 'P':          /* -P path/to/cfg:path/to/script or -P path/to/cfg or -P :path/to/script */
p = strchr(optarg, ':');
if (p) {
*p = '\0';
g_script_path = strdup(p + 1);
}
if (p != optarg)
g_config_path = strdup(optarg);
diagnostics(2, "cfg=%s, script=%s", g_config_path, g_script_path);
break;
case 's':
if (optarg && optarg[0] == 'e') {
if (sscanf(optarg, "e%lf", &xx) == 1 && xx > 0)
g_png_equation_scale = xx;
else
diagnostics(WARNING, "Equation scale (-se #) is not positive, ignoring");
}
if (optarg && optarg[0] == 'f') {
if (sscanf(optarg, "f%lf", &xx) == 1 && xx > 0)
g_png_figure_scale = xx;
else
diagnostics(WARNING, "Figure scale (-sf #) is not positive, ignoring");
}
break;
case 'S':
g_field_separator = ';';
break;
case 'T':
g_tmp_path = strdup(optarg);
break;
case 'W':
g_RTF_warnings = TRUE;
break;
case 'Z':
g_safety_braces = FALSE;
g_safety_braces = *optarg - '0';
if (g_safety_braces < 0 || g_safety_braces > 9) {
diagnostics(WARNING, "Number of safety braces (-Z#) must be 0-9");
print_usage();
}
break;


case 'h':
case '?':
default:
print_usage();
}
}


argc -= optind;
argv += optind;


if (argc > 1) {
diagnostics(WARNING, "Only a single file can be processed at a time");
diagnostics(ERROR, " Type \"latex2rtf -h\" for help");
}


/* Parse filename.    Extract directory if possible.    Beware of stdin cases */


if (argc == 1 && strcmp(*argv, "-") != 0) { /* filename exists and != "-" */
char *s, *t;


basename = strdup(*argv);   /* parse filename */
s = strrchr(basename, PATHSEP);
if (s != NULL) {
g_home_dir = strdup(basename);  /* parse /tmp/file.tex */
t = strdup(s + 1);
free(basename);
basename = PATHSEP;       /* basename = file.tex *t/
s = strrchr(g_home_dir, PATHSEP);
*(s + 1) = '\0';    /* g_home_dir = /tmp/ */
}


t = strstr(basename, ".ltx");   /* remove .ltx if present */
if (t != NULL) {
*t = '\0';
g_tex_name = strdup_together(basename, ".ltx");


} else {


t = strstr(basename, ".tex");   /* remove .tex if present */
if (t != NULL)
*t = '\0';


g_tex_name = strdup_together(basename, ".tex");
}


if (g_rtf_name == NULL)
g_rtf_name = strdup_together(basename, ".rtf");
}


if (g_aux_name == NULL && basename != NULL)
g_aux_name = strdup_together(basename, ".aux");


if (g_bbl_name == NULL && basename != NULL)
g_bbl_name = strdup_together(basename, ".bbl");


if (g_toc_name == NULL && basename != NULL)
g_toc_name = strdup_together(basename, ".toc");


if (g_lof_name == NULL && basename != NULL)
g_lof_name = strdup_together(basename, ".lof");


if (g_lot_name == NULL && basename != NULL)
g_lot_name = strdup_together(basename, ".lot");


if (g_fff_name == NULL && basename != NULL)
g_fff_name = strdup_together(basename, ".fff");


if (g_ttt_name == NULL && basename != NULL)
g_ttt_name = strdup_together(basename, ".ttt");


if (basename) {
diagnostics(3, "latex filename is <%s>", g_tex_name);
diagnostics(3, "  rtf filename is <%s>", g_rtf_name);
diagnostics(3, "  aux filename is <%s>", g_aux_name);
diagnostics(3, "  bbl filename is <%s>", g_bbl_name);
diagnostics(3, "home directory is <%s>", (g_home_dir) ? g_home_dir : "");
}


ReadCfg();


if (PushSource(g_tex_name, NULL) == 0) {
OpenRtfFile(g_rtf_name, &fRtf);


InitializeDocumentFont(TexFontNumber("Roman"), 20, F_SHAPE_UPRIGHT, F_SERIES_MEDIUM);
PushTrackLineNumber(TRUE);


ConvertWholeDocument();
PopSource();
CloseRtf(&fRtf);
printf("\n");


/*        debug_malloc();*/


return 0;
} else {
printf("\n");
return 1;
}
}


static void SetEndianness(void)


/*
purpose : Figure out endianness of machine.     Needed for graphics support
*/
{
unsigned int endian_test = (unsigned int) 0xaabbccdd;
unsigned char endian_test_char = *(unsigned char *) &endian_test;


if (endian_test_char == 0xdd)
g_little_endian = TRUE;
}



static void ConvertWholeDocument(void)
{
char *body, *sec_head, *sec_head2, *label;
char t[] = "\\begin{document}";


PushEnvironment(DOCUMENT_MODE);  /* because we use ConvertString in preamble.c */
PushEnvironment(PREAMBLE_MODE);
SetTexMode(MODE_VERTICAL);
ConvertLatexPreamble();
WriteRtfHeader();
ConvertString(t);


g_processing_preamble = FALSE;
getSection(&body, &sec_head, &label);


diagnostics(2, "*******************\nbody=%s", (body) ? body : "<empty>");
diagnostics(2, "*******************\nsec_head=%s", (sec_head) ? sec_head : "<none>");
diagnostics(2, "*******************\nlabel=%s", (g_section_label) ? g_section_label : "<none>");
ConvertString(body);
free(body);
if (label)
free(label);


while (sec_head) {
getSection(&body, &sec_head2, &g_section_label);
label = ExtractLabelTag(sec_head);
if (label) {
if (g_section_label)
free(g_section_label);
g_section_label = label;
}
diagnostics(2, "\n========this section head==========\n%s", (sec_head) ? sec_head : "<none>");
diagnostics(2, "\n============ label ================\nlabel=%s",
(g_section_label) ? g_section_label : "<none>");
diagnostics(2,
"\n==============body=================\n%s\n=========end    body=================", (body) ? body : "<empty>");
diagnostics(2, "\n========next section head==========\n%s", (sec_head2) ? sec_head2 : "<none>");
ConvertString(sec_head);
ConvertString(body);
free(body);
free(sec_head);
sec_head = sec_head2;
}


if (g_endfloat_figures && g_fff_name) {
g_endfloat_figures = FALSE;
if (PushSource(g_fff_name, NULL) == 0) {
CmdNewPage(NewPage);
CmdListOf(LIST_OF_FIGURES);
getSection(&body, &sec_head2, &g_section_label);
ConvertString(sec_head);
ConvertString(body);
if (g_section_label) free(g_section_label);
free(body);
free(sec_head);
}
}


if (g_endfloat_tables && g_ttt_name) {
g_endfloat_tables = FALSE;
if (PushSource(g_ttt_name, NULL) == 0) {
CmdNewPage(NewPage);
CmdListOf(LIST_OF_TABLES);
getSection(&body, &sec_head2, &g_section_label);
ConvertString(sec_head);
ConvertString(body);
if (g_section_label) free(g_section_label);
free(body);
free(sec_head);
}
}
}


static void print_version(void)
{
fprintf(stdout, "latex2rtf %s\n\n", Version);
fprintf(stdout, "Copyright (C) 2004 Free Software Foundation, Inc.\n");
fprintf(stdout, "This is free software; see the source for copying conditions.  There is NO\n");
fprintf(stdout, "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n");
fprintf(stdout, "Written by Prahl, Lehner, Granzer, Dorner, Polzer, Trisko, Schlatterbeck.\n");


/*        fprintf(stdout, "RTFPATH = '%s'\n", getenv("RTFPATH"));*/
}


static void print_usage(void)
{
char *s;


fprintf(stdout, "`%s' converts text files in LaTeX format to rich text format (RTF).\n\n", progname);
fprintf(stdout, "Usage:  %s [options] input[.tex]\n\n", progname);
fprintf(stdout, "Options:\n");
fprintf(stdout, "  -a auxfile       use LaTeX auxfile rather than input.aux\n");
fprintf(stdout, "  -b bblfile       use BibTex bblfile rather than input.bbl)\n");
fprintf(stdout, "  -C codepage      latex encoding charset (latin1, cp850, raw, etc.)\n");
fprintf(stdout, "  -d level         debugging output (level is 0-6)\n");
fprintf(stdout, "  -f#              field handling\n");
fprintf(stdout, "       -f0          do not use fields\n");
fprintf(stdout, "       -f1          use fields for equations but not \\ref{} & \\cite{}\n");
fprintf(stdout, "       -f2          use fields for \\cite{} & \\ref{}, but not equations\n");
fprintf(stdout, "       -f3          use fields when possible (default)\n");
fprintf(stdout, "  -F               use LaTeX to convert all figures to bitmaps\n");
fprintf(stdout, "  -D dpi           number of dots per inch for bitmaps\n");
fprintf(stdout, "  -h               display help\n");
fprintf(stdout, "  -i language      idiom or language (e.g., german, french)\n");
fprintf(stdout, "  -l               use latin1 encoding (default)\n");
fprintf(stdout, "  -M#              math equation handling\n");
fprintf(stdout, "       -M1          displayed equations to RTF\n");
fprintf(stdout, "       -M2          inline equations to RTF\n");
fprintf(stdout, "       -M3          inline and displayed equations to RTF (default)\n");
fprintf(stdout, "       -M4          displayed equations to bitmap\n");
fprintf(stdout, "       -M6          inline equations to RTF and displayed equations to bitmaps\n");
fprintf(stdout, "       -M8          inline equations to bitmap\n");
fprintf(stdout, "       -M12         inline and displayed equations to bitmaps\n");
fprintf(stdout, "       -M16         insert Word comment field that the original equation text\n");
fprintf(stdout, "  -o outputfile    file for RTF output\n");
fprintf(stdout, "  -p               option to avoid bug in Word for some equations\n");
fprintf(stdout, "  -P path          paths to *.cfg & latex2png\n");
fprintf(stdout, "  -S               use ';' to separate args in RTF fields\n");
fprintf(stdout, "  -se#             scale factor for bitmap equations\n");
fprintf(stdout, "  -sf#             scale factor for bitmap figures\n");
fprintf(stdout, "  -T /path/to/tmp  temporary directory\n");
fprintf(stdout, "  -v               version information\n");
fprintf(stdout, "  -V               version information\n");
fprintf(stdout, "  -W               include warnings in RTF\n");
fprintf(stdout, "  -Z#              add # of '}'s at end of rtf file (# is 0-9)\n\n");
fprintf(stdout, "Examples:\n");
fprintf(stdout, "  latex2rtf foo                       convert foo.tex to foo.rtf\n");
fprintf(stdout, "  latex2rtf <foo >foo.RTF             convert foo to foo.RTF\n");
fprintf(stdout, "  latex2rtf -P ./cfg/:./scripts/ foo  use alternate cfg and latex2png files\n");
fprintf(stdout, "  latex2rtf -M12 foo                  replace equations with bitmaps\n");
fprintf(stdout, "  latex2rtf -i russian foo            assume russian tex conventions\n");
fprintf(stdout, "  latex2rtf -C raw foo                retain font encoding in rtf file\n");
fprintf(stdout, "  latex2rtf -f0 foo                   create foo.rtf without fields\n");
fprintf(stdout, "  latex2rtf -d4 foo                   lots of debugging information\n\n");
fprintf(stdout, "Report bugs to <latex2rtf-developers@lists.sourceforge.net>\n\n");
fprintf(stdout, "$RTFPATH designates the directory for configuration files (*.cfg)\n");
s = getenv("RTFPATH");
fprintf(stdout, "$RTFPATH = '%s'\n\n", (s) ? s : "not defined");
s = CFGDIR;
fprintf(stdout, "CFGDIR compiled-in directory for configuration files (*.cfg)\n");
fprintf(stdout, "CFGDIR  = '%s'\n\n", (s) ? s : "not defined");
fprintf(stdout, "latex2rtf %s\n", Version);
exit(1);
}


void diagnostics(int level, char *format, ...)


/****************************************************************************
purpose: Writes the message to stderr depending on debugging level
****************************************************************************/
{
char buffer[512], *buff_ptr;
va_list apf;
int i, iEnvCount;


buff_ptr = buffer;


va_start(apf, format);


if (level <= g_verbosity_level) {


iEnvCount = CurrentEnvironmentCount();


fprintf(stderr, "\n%s:%d ",CurrentFileName(),CurrentLineNumber());
switch (level) {
case 0:
fprintf(stderr, "Error! ");
break;
case 1:
if (g_RTF_warnings) {
vsnprintf(buffer, 512, format, apf);
fprintRTF("{\\plain\\cf2 [latex2rtf:");
while (*buff_ptr) {
putRtfChar(*buff_ptr);
buff_ptr++;
}
fprintRTF("]}");
}
break;
case 5:
case 6:
fprintf(stderr, " rec=%d ", RecursionLevel);
/*fall through */
case 2:
case 3:
case 4:
for (i = 0; i < BraceLevel; i++)
fprintf(stderr, "{");
for (i = 8; i > BraceLevel; i--)
fprintf(stderr, " ");


for (i = 0; i < RecursionLevel; i++)
fprintf(stderr, "  ");
break;
default:
break;
}
vfprintf(stderr, format, apf);
}
va_end(apf);


if (level == 0) {
fprintf(stderr, "\n");
fflush(stderr);
if (fRtf)
fflush(fRtf);


exit(EXIT_FAILURE);
}
}


static void InitializeLatexLengths(void)
{
/* Default Page Sizes */
setLength("pageheight", 795 * 20);
setLength("hoffset", 0 * 20);
setLength("oddsidemargin", 62 * 20);
setLength("headheight", 12 * 20);
setLength("textheight", 550 * 20);
setLength("footskip", 30 * 20);
setLength("marginparpush", 5 * 20);


setLength("pagewidth", 614 * 20);
setLength("voffset", 0 * 20);
setLength("topmargin", 18 * 20);
setLength("headsep", 25 * 20);
setLength("textwidth", 345 * 20);
setLength("columnsep", 10 * 20);
setLength("evensidemargin", 11 * 20);


/* Default Paragraph Sizes */
setLength("baselineskip", 12 * 20);
setLength("parindent", 15 * 20);
setLength("parskip", 0 * 20);


setCounter("page", 0);
setCounter("chapter", 0);
setCounter("section", 0);
setCounter("subsection", 0);
setCounter("subsubsection", 0);
setCounter("paragraph", 0);
setCounter("subparagraph", 0);
setCounter("figure", 0);
setCounter("table", 0);
setCounter("equation", 0);
setCounter("footnote", 0);
setCounter("mpfootnote", 0);
setCounter("secnumdepth", 2);
setCounter("endfloatfigure", 0);
setCounter("endfloattable", 0);


/* vertical separation lengths */
setLength("topsep", 3 * 20);
setLength("partopsep", 2 * 20);
setLength("parsep", (int) (2.5 * 20));
setLength("itemsep", 0 * 20);
setLength("labelwidth", 0 * 20);
setLength("labelsep", 0 * 20);
setLength("itemindent", 0 * 20);
setLength("listparindent", 0 * 20);
setLength("leftmargin", 0 * 20);
setLength("floatsep", 0 * 20);
setLength("intextsep", 0 * 20);
setLength("textfloatsep", 0 * 20);
setLength("abovedisplayskip", 0 * 20);
setLength("belowdisplayskip", 0 * 20);
setLength("abovecaptionskip", 0 * 20);
setLength("belowcaptionskip", 0 * 20);
setLength("intextsep", 0 * 20);


setLength("smallskipamount", 3 * 20);
setLength("medskipamount", 6 * 20);
setLength("bigskipamount", 12 * 20);


setLength("marginparsep", 10 * 20);
}


static void RemoveInterpretCommentString(char *s)


/****************************************************************************
purpose: removes %InterpretCommentString from preamble (usually "%latex2rtf:")
****************************************************************************/
{
char *p, *t;
int n = strlen(InterpretCommentString);


t = s;
while ((p = strstr(t, InterpretCommentString))) {
t = p - 1;
if (*t == '%')
strcpy(t, t + n + 1);
else
t += n + 1;
}
}


static void ConvertLatexPreamble(void)


/****************************************************************************
purpose: reads the LaTeX preamble (to \begin{document} ) for the file
****************************************************************************/
{
FILE *hidden;
char t[] = "\\begin{document}";


diagnostics(4, "Reading LaTeX Preamble");
hidden = fRtf;
fRtf = stderr;


g_preamble = getTexUntil(t, 1);
RemoveInterpretCommentString(g_preamble);


diagnostics(4, "Entering ConvertString() from ConvertLatexPreamble <%s>", g_preamble);
ConvertString(g_preamble);
diagnostics(4, "Exiting ConvertString() from ConvertLatexPreamble");


fRtf = hidden;
}



void OpenRtfFile(char *filename, FILE ** f)


/****************************************************************************
purpose: creates output file and writes RTF-header.
params: filename - name of outputfile, possibly NULL for already open file
f - pointer to filepointer to store file ID
****************************************************************************/
{
char *name;


if (filename == NULL) {
diagnostics(4, "Writing RTF to stdout");
*f = stdout;


} else {


if (g_home_dir)
name = strdup_together(g_home_dir, filename);
else
name = strdup(filename);


diagnostics(3, "Opening RTF file <%s>", name);
*f = fopen(name, "w");


if (*f == NULL)
diagnostics(ERROR, "Error opening RTF file <%s>\n", name);


free(name);
}
}


void CloseRtf(FILE ** f)


/****************************************************************************
purpose: closes output file.
params: f - pointer to filepointer to invalidate
globals: g_tex_name;
****************************************************************************/
{
int i;


CmdEndParagraph(0);
if (BraceLevel > 1)
diagnostics(WARNING, "Mismatched '{' in RTF file, Conversion may cause problems.");


if (BraceLevel - 1 > g_safety_braces)
diagnostics(WARNING, "Try translating with 'latex2rtf -Z%d %s'", BraceLevel - 1, g_tex_name);


fprintf(*f, "}\n");
for (i = 0; i < g_safety_braces; i++)
fprintf(*f, "}");
if (*f != stdout) {
if (fclose(*f) == EOF) {
diagnostics(WARNING, "Error closing RTF-File");
}
}
*f = NULL;
diagnostics(4, "Closed RTF file");
}


void putRtfChar(char cThis)


/****************************************************************************
purpose: output filter to escape characters written to an RTF file
all output to the RTF file passes through this routine or the one below
****************************************************************************/
{
if ((unsigned char) cThis > 127)
WriteEightBitChar(cThis);
else if (cThis == '\\')
fprintf(fRtf, "\\\\");
else if (cThis == '{')
fprintf(fRtf, "\\{");
else if (cThis == '}')
fprintf(fRtf, "\\}");
else if (cThis == '\n')
fprintf(fRtf, "\n\\par ");
else
fputc(cThis, fRtf);
}


void fprintRTF(char *format, ...)


/****************************************************************************
purpose: output filter to track of brace depth and font settings
all output to the RTF file passes through this routine or the one above
****************************************************************************/
{
char buffer[1024];
char *text;
char last='\0';


va_list apf;


va_start(apf, format);
vsnprintf(buffer, 1024, format, apf);
va_end(apf);
text = buffer;


while (*text) {


if ((unsigned char) *text > 127) {


WriteEightBitChar(text[0]);


} else {
fputc(*text, fRtf);


if (*text == '{' && last != '\\')
PushFontSettings();


if (*text == '}' && last != '\\')
PopFontSettings();


if (*text == '\\' && last != '\\')
MonitorFontChanges(text);
}
last= *text;
text++;
}
}


char *getTmpPath(void)


/****************************************************************************
purpose: return the directory to store temporary files
****************************************************************************/
{
#if defined(MSDOS) || defined(MACINTOSH) || defined(__MWERKS__)


return strdup("");


#else


char *t, *u;
char pathsep_str[2] = { PATHSEP, 0 };   /* for os2 or w32 "unix" compiler */


/* first use any temporary directory specified as an option */
if (g_tmp_path)
t = strdup(g_tmp_path);


/* next try the environment variable TMPDIR */
else if ((u = getenv("TMPDIR")) != NULL)
t = strdup(u);


/* finally just return "/tmp/" */
else
t = strdup("/tmp/");


/* append a final '/' if missing */
if (*(t + strlen(t) - 1) != PATHSEP) {
u = strdup_together(t, pathsep_str);
free(t);
return u;
}


return t;
#endif
}


char *my_strdup(const char *str)


/****************************************************************************
purpose: duplicate string --- exists to ease porting
****************************************************************************/
{
char *s = NULL;
unsigned long strsize;


strsize = strlen(str);
s = (char *) malloc(strsize + 1);
*s = '\0';
if (s == NULL)
diagnostics(ERROR, "Cannot allocate memory to duplicate string");
strcpy(s, str);


/*    diagnostics(3,"ptr %x",(unsigned long)s);*/
return s;
}


FILE *my_fopen(char *path, char *mode)


/****************************************************************************
purpose: opens "g_home_dir/path"  and
****************************************************************************/
{
char *name;
FILE *p;


diagnostics(3, "Opening <%s>, mode=[%s]", path, mode);


if (path == NULL || mode == NULL)
return (NULL);


if (g_home_dir == NULL)
name = strdup(path);
else
name = strdup_together(g_home_dir, path);


diagnostics(3, "Opening <%s>", name);
p = fopen(name, mode);


if (p == NULL && strstr(path, ".tex"))
p = (FILE *) open_cfg(path, FALSE);


if (p == NULL) {
diagnostics(WARNING, "Cannot open <%s>", name);
fflush(NULL);
}


free(name);
return p;
}


void debug_malloc(void)
{
char c;


diagnostics(1, "Malloc Debugging --- press return to continue");
fflush(NULL);
fscanf(stdin, "%c", &c);
}


MAIN.H
---------


/* $Id: main.h,v 1.69 2005/01/18 06:19:46 prahl Exp $ */


#if defined(UNIX)
#define ENVSEP ':'
#define PATHSEP '/'
#endif


#if defined(MSDOS) || defined(OS2)
#define ENVSEP ';'
#define PATHSEP '\\'
#endif


#if defined(VMS)
#define ENVSEP ','
#define PATHSEP ''
#endif


#if defined(MAC_CLASSIC)
#define ENVSEP '^'
#define PATHSEP ':'
#include "MainMain.h"
#endif


#ifdef HAS_STRDUP
#else
#define strdup my_strdup
#endif


#ifndef SEEK_SET
#define SEEK_SET 0
#define SEEK_CUR 1
#endif


#define ERROR 0
#define WARNING 1


#define MAXCOMMANDLEN 100


/* available values for alignment */
#define LEFT      'l'
#define RIGHT      'r'
#define CENTERED  'c'
#define JUSTIFIED 'j'


#define PATHMAX 255


/*** error constants ***/
#include <assert.h>
#include <stdio.h>


/*** interpret comment lines that follow the '%' with this string ***/
extern const char  * InterpretCommentString;


typedef int        bool;


void            diagnostics(int level, char *format,...);


extern /* @dependent@ */ FILE *fRtf;    /* file pointer to RTF file */
extern            char *g_aux_name;
extern            char *g_toc_name;
extern            char *g_lof_name;
extern            char *g_lot_name;
extern            char *g_fff_name;
extern            char *g_bbl_name;
extern            char *g_home_dir;
extern            char *progname;            /* name of the executable file */


extern bool        GermanMode;
extern bool        FrenchMode;
extern bool        RussianMode;
extern bool        CzechMode;
extern bool        pagenumbering;
extern int        headings;


extern int        g_verbosity_level;
extern int        RecursionLevel;
extern int        g_left_margin_indent;
extern int        g_right_margin_indent;
extern char        alignment;


/* table  & tabbing variables */
extern char        *colFmt;
extern long        pos_begin_kill;
extern int        tabcounter;
extern int        colCount;
extern int        actCol;
extern int        g_equation_column;
extern int        tabcounter;


extern bool        twocolumn;
extern bool        titlepage;
extern bool        g_processing_equation;
extern bool        g_processing_preamble;
extern bool        g_processing_figure;
extern bool        g_processing_table;
extern bool        g_processing_tabbing;
extern bool        g_processing_tabular;
extern bool        g_processing_eqnarray;
extern int        g_processing_arrays;
extern int        g_processing_fields;
extern int        g_dots_per_inch;


extern int        g_document_type;
extern int        g_document_bibstyle;


extern bool        g_fields_use_EQ;
extern bool        g_fields_use_REF;


extern int        g_equation_number;
extern bool        g_escape_parent;
extern bool        g_show_equation_number;
extern int        g_enumerate_depth;
extern bool        g_suppress_equation_number;
extern bool        g_aux_file_missing;
extern bool        g_bbl_file_missing;
extern char        g_charset_encoding_name[20];
extern int        g_fcharset_number;
extern int      g_graphics_package;


extern char        *g_figure_label;
extern char        *g_table_label;
extern char        *g_equation_label;
extern char        *g_section_label;
extern char        *g_config_path;
extern char        *g_script_path;
extern char        g_field_separator;
extern char        *g_preamble;


extern double    g_png_equation_scale;
extern double    g_png_figure_scale;
extern bool        g_latex_figures;
extern bool        g_endfloat_figures;
extern bool        g_endfloat_tables;
extern bool        g_endfloat_markers;


extern bool        g_equation_inline_rtf;
extern bool        g_equation_display_rtf;
extern bool        g_equation_inline_bitmap;
extern bool        g_equation_display_bitmap;
extern bool        g_equation_comment;
extern bool        g_little_endian;
extern bool        g_tableofcontents;


void fprintRTF(char *format, ...);
void putRtfChar(char cThis);
char *getTmpPath(void);
char *my_strdup(const char *str);
FILE *my_fopen(char *path, char *mode);


void debug_malloc(void);


STRING.H
----------



/***
*string.h - declarations for string manipulation functions
*
*       Copyright (c) Microsoft Corporation. All rights reserved.
*
*Purpose:
*       This file contains the function declarations for the string
*       manipulation functions.
*       [ANSI/System V]
*
*       [Public]
*
****/


#if     _MSC_VER > 1000
#pragma once
#endif


#ifndef _INC_STRING
#define _INC_STRING


#include <crtdefs.h>


#ifdef  __cplusplus
extern "C" {
#endif


#ifndef _NLSCMP_DEFINED
#define _NLSCMPERROR    2147483647  /* currently == INT_MAX */
#define _NLSCMP_DEFINED
#endif


/* Define NULL pointer value */
#ifndef NULL
#ifdef __cplusplus
#define NULL    0
#else
#define NULL    ((void *)0)
#endif
#endif


/* For backwards compatibility */
#define _WConst_return _CONST_RETURN


/* Function prototypes */
#ifndef _CRT_MEMORY_DEFINED
#define _CRT_MEMORY_DEFINED
_CRTIMP void *  __cdecl _memccpy( __out_bcount_opt(_MaxCount) void * _Dst, __in const void * _Src, __in int _Val, __in size_t _MaxCount);
_CRTIMP __checkReturn _CONST_RETURN void *  __cdecl memchr( __in_bcount_opt(_MaxCount) const void * _Buf , __in int _Val, __in size_t _MaxCount);
_CRTIMP __checkReturn int     __cdecl _memicmp(__in_bcount_opt(_Size) const void * _Buf1, __in_bcount_opt(_Size) const void * _Buf2, __in size_t _Size);
_CRTIMP __checkReturn int     __cdecl _memicmp_l(__in_bcount_opt(_Size) const void * _Buf1, __in_bcount_opt(_Size) const void * _Buf2, __in size_t _Size, __in_opt _locale_t _Locale);
__checkReturn int     __cdecl memcmp(__in_bcount_opt(_Size) const void * _Buf1, __in_bcount_opt(_Size) const void * _Buf2, __in size_t _Size);
_CRT_INSECURE_DEPRECATE_MEMORY(memcpy_s) void *  __cdecl memcpy(__out_bcount_full_opt(_Size) void * _Dst, __in_bcount_opt(_Size) const void * _Src, __in size_t _Size);
#if __STDC_WANT_SECURE_LIB__
_CRTIMP errno_t  __cdecl memcpy_s(__out_bcount_part_opt(_DstSize, _MaxCount) void * _Dst, __in rsize_t _DstSize, __in_bcount_opt(_MaxCount) const void * _Src, __in rsize_t _MaxCount);
#endif
void *  __cdecl memset(__out_bcount_full_opt(_Size) void * _Dst, __in int _Val, __in size_t _Size);


#if     !__STDC__
/* Non-ANSI names for compatibility */
_CRT_NONSTDC_DEPRECATE(_memccpy) _CRTIMP void * __cdecl memccpy(__out_bcount_opt(_Size) void * _Dst, __in_bcount_opt(_Size) const void * _Src, __in int _Val, __in size_t _Size);
_CRT_NONSTDC_DEPRECATE(_memicmp) _CRTIMP __checkReturn int __cdecl memicmp(__in_bcount_opt(_Size) const void * _Buf1, __in_bcount_opt(_Size) const void * _Buf2, __in size_t _Size);
#endif  /* __STDC__ */


#endif


_CRT_INSECURE_DEPRECATE(_strset_s) char *  __cdecl _strset(__inout_z char * _Str, __in int _Val);
_CRTIMP_ALTERNATIVE __checkReturn_wat errno_t __cdecl _strset_s(__inout_ecount_z(_DstSize) char * _Dst, __in size_t _DstSize, __in int _Value);
#if __STDC_WANT_SECURE_LIB__
_CRTIMP_ALTERNATIVE __checkReturn_wat errno_t __cdecl strcpy_s(__out_ecount_z(_DstSize) char * _Dst, __in rsize_t _DstSize, __in_z const char * _Src);
#endif
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(errno_t, strcpy_s, __out_ecount_z(_Size) char, _Dest, __in_z const char *, _Source)
__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1(char *, __RETURN_POLICY_DST, __EMPTY_DECLSPEC, strcpy, __out_z char, _Dest, __in_z const char *, _Source)
#if __STDC_WANT_SECURE_LIB__
_CRTIMP_ALTERNATIVE __checkReturn_wat errno_t __cdecl strcat_s(__inout_ecount_z(_DstSize) char * _Dst, __in rsize_t _DstSize, __in_z const char * _Src);
#endif
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(errno_t, strcat_s, __inout_ecount_z(_Size) char, _Dest, __in_z const char *, _Source)
__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1(char *, __RETURN_POLICY_DST, __EMPTY_DECLSPEC, strcat, __inout_z char, _Dest, __in_z const char *, _Source)
__checkReturn int     __cdecl strcmp(__in_z const char * _Str1, __in_z const char * _Str2);
__checkReturn size_t  __cdecl strlen(__in_z  const char * _Str);
_CRTIMP __checkReturn size_t  __cdecl strnlen(__in_ecount_z(_MaxCount)  const char * _Str, __in size_t _MaxCount);
#if __STDC_WANT_SECURE_LIB__ && !defined (__midl)
static __inline __checkReturn size_t  __CRTDECL strnlen_s(__in_ecount_z(_MaxCount)  const char * _Str, __in size_t _MaxCount)
{
return strnlen(_Str, _MaxCount);
}
#endif
#if __STDC_WANT_SECURE_LIB__
_CRTIMP __checkReturn_wat errno_t __cdecl memmove_s(__out_bcount_part_opt(_DstSize,_MaxCount) void * _Dst, __in rsize_t _DstSize, __in_bcount_opt(_MaxCount) const void * _Src, __in rsize_t _MaxCount);
#endif


#if     defined(_M_IA64)
_CRT_INSECURE_DEPRECATE_MEMORY(memmove_s) void *  __cdecl memmove(__out_bcount_full_opt(_Size) void * _Dst, __in_bcount_opt(_Size) const void * _Src, __in size_t _Size);
#else  /* defined (_M_IA64) */
_CRTIMP _CRT_INSECURE_DEPRECATE_MEMORY(memmove_s) void *  __cdecl memmove(__out_bcount_full_opt(_Size) void * _Dst, __in_bcount_opt(_Size) const void * _Src, __in size_t _Size);
#endif  /* defined (_M_IA64) */


#if defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC)
#pragma push_macro("_strdup")
#undef _strdup
#endif


_CRTIMP __checkReturn char *  __cdecl _strdup(__in_z_opt const char * _Src);


#if defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC)
#pragma pop_macro("_strdup")
#endif


_CRTIMP __checkReturn _CONST_RETURN char *  __cdecl strchr(__in_z const char * _Str, __in int _Val);
_CRTIMP __checkReturn int     __cdecl _stricmp(__in_z  const char * _Str1, __in_z  const char * _Str2);
_CRTIMP __checkReturn int     __cdecl _strcmpi(__in_z  const char * _Str1, __in_z  const char * _Str2);
_CRTIMP __checkReturn int     __cdecl _stricmp_l(__in_z  const char * _Str1, __in_z  const char * _Str2, __in_opt _locale_t _Locale);
_CRTIMP __checkReturn int     __cdecl strcoll(__in_z  const char * _Str1, __in_z  const  char * _Str2);
_CRTIMP __checkReturn int     __cdecl _strcoll_l(__in_z  const char * _Str1, __in_z  const char * _Str2, __in_opt _locale_t _Locale);
_CRTIMP __checkReturn int     __cdecl _stricoll(__in_z  const char * _Str1, __in_z  const char * _Str2);
_CRTIMP __checkReturn int     __cdecl _stricoll_l(__in_z  const char * _Str1, __in_z  const char * _Str2, __in_opt _locale_t _Locale);
_CRTIMP __checkReturn int     __cdecl _strncoll  (__in_z const char * _Str1, __in_z const char * _Str2, __in size_t _MaxCount);
_CRTIMP __checkReturn int     __cdecl _strncoll_l(__in_z const char * _Str1, __in_z const char * _Str2, __in size_t _MaxCount, __in_opt _locale_t _Locale);
_CRTIMP __checkReturn int     __cdecl _strnicoll (__in_z const char * _Str1, __in_z const char * _Str2, __in size_t _MaxCount);
_CRTIMP __checkReturn int     __cdecl _strnicoll_l(__in_z const char * _Str1, __in_z const char * _Str2, __in size_t _MaxCount, __in_opt _locale_t _Locale);
_CRTIMP __checkReturn size_t  __cdecl strcspn(__in_z  const char * _Str, __in_z  const char * _Control);
_CRT_INSECURE_DEPRECATE(_strerror_s) _CRTIMP __checkReturn char *  __cdecl _strerror(__in_z_opt const char * _ErrMsg);
_CRTIMP __checkReturn_wat errno_t __cdecl _strerror_s(__out_ecount_z(_SizeInBytes) char * _Buf, __in size_t _SizeInBytes, __in_z_opt const char * _ErrMsg);
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(errno_t, _strerror_s, __out_ecount(_Size) char, _Buffer, __in_z_opt const char *, _ErrorMessage)
_CRT_INSECURE_DEPRECATE(strerror_s) _CRTIMP __checkReturn char *  __cdecl strerror(__in int);
#if __STDC_WANT_SECURE_LIB__
_CRTIMP __checkReturn_wat errno_t __cdecl strerror_s(__out_ecount_z(_SizeInBytes) char * _Buf, __in size_t _SizeInBytes, __in int _ErrNum);
#endif
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(errno_t, strerror_s, __out_ecount(_Size) char, _Buffer, __in int, _ErrorMessage)
_CRTIMP __checkReturn_wat errno_t __cdecl _strlwr_s(__inout_ecount_z(_Size) char * _Str, __in size_t _Size);
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_0(errno_t, _strlwr_s, __inout_ecount_z(_Size) char, _String)
__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_0(char *, __RETURN_POLICY_DST, _CRTIMP, _strlwr, __inout_z char, _String)
_CRTIMP __checkReturn_wat errno_t __cdecl _strlwr_s_l(__inout_ecount_z(_Size) char * _Str, __in size_t _Size, __in_opt _locale_t _Locale);
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(errno_t, _strlwr_s_l, __inout_ecount_z(_Size) char, _String, __in_opt _locale_t, _Locale)
__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1_EX(char *, __RETURN_POLICY_DST, _CRTIMP, _strlwr_l, _strlwr_s_l, __inout_z char, _String, __in_opt _locale_t, _Locale)
#if __STDC_WANT_SECURE_LIB__
_CRTIMP_ALTERNATIVE __checkReturn_wat errno_t __cdecl strncat_s(__inout_ecount_z(_DstSize) char * _Dst, __in rsize_t _DstSize, __in_z const char * _Src, __in rsize_t _MaxCount);
#endif
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_2(errno_t, strncat_s, __inout_ecount_z(_Size) char, _Dest, __in_z const char *, _Source, __in size_t, _Count)
#pragma warning(push)
#pragma warning(disable:4609 6059)
/* prefast noise VSW 489802 */
__DEFINE_CPP_OVERLOAD_STANDARD_NFUNC_0_2_EX(char *, __RETURN_POLICY_DST, _CRTIMP, strncat, strncat_s, __inout_z char, __inout_ecount_z(_Count) char, _Dest, __in_z const char *, _Source, __in size_t, _Count)
#pragma warning(pop)
#if     defined(_M_IA64)
__checkReturn int     __cdecl strncmp(__in_z  const char * _Str1, __in_z const char * _Str2, __in size_t _MaxCount);
#else
_CRTIMP __checkReturn int     __cdecl strncmp(__in_z const char * _Str1, __in_z const char * _Str2, __in size_t _MaxCount);
#endif
_CRTIMP __checkReturn int     __cdecl _strnicmp(__in_z const char * _Str1, __in_z const char * _Str2, __in size_t _MaxCount);
_CRTIMP __checkReturn int     __cdecl _strnicmp_l(__in_z const char * _Str1, __in_z const char * _Str2, __in size_t _MaxCount, __in_opt _locale_t _Locale);
#if __STDC_WANT_SECURE_LIB__
_CRTIMP_ALTERNATIVE __checkReturn_wat errno_t __cdecl strncpy_s(__out_ecount_z(_DstSize) char * _Dst, __in rsize_t _DstSize, __in_z_opt const char * _Src, __in rsize_t _MaxCount);
#endif
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_2(errno_t, strncpy_s, __out_ecount(_Size) char, _Dest, __in_z const char *, _Source, __in size_t, _Count)
__DEFINE_CPP_OVERLOAD_STANDARD_NFUNC_0_2_EX(char *, __RETURN_POLICY_DST, _CRTIMP_NOIA64, strncpy, strncpy_s, __out_z char, __out_ecount(_Count) char, _Dest, __in_z const char *, _Source, __in size_t, _Count)
_CRT_INSECURE_DEPRECATE(_strnset_s) _CRTIMP char *  __cdecl _strnset(__inout_z char * _Str, __in int _Val, __in size_t _MaxCount);
_CRTIMP_ALTERNATIVE __checkReturn_wat errno_t __cdecl _strnset_s(__inout_ecount_z(_Size) char * _Str, __in size_t _Size, __in int _Val, __in size_t _MaxCount);
_CRTIMP __checkReturn _CONST_RETURN char *  __cdecl strpbrk(__in_z const char * _Str, __in_z const char * _Control);
_CRTIMP __checkReturn _CONST_RETURN char *  __cdecl strrchr(__in_z const char * _Str, __in int _Ch);
_CRTIMP char *  __cdecl _strrev(__inout_z char * _Str);
_CRTIMP __checkReturn size_t  __cdecl strspn(__in_z const char * _Str, __in_z const char * _Control);
_CRTIMP __checkReturn _CONST_RETURN char *  __cdecl strstr(__in_z const char * _Str, __in_z const char * _SubStr);
_CRT_INSECURE_DEPRECATE(strtok_s) _CRTIMP __checkReturn char *  __cdecl strtok(__inout_z_opt char * _Str, __in_z const char * _Delim);
#if __STDC_WANT_SECURE_LIB__
_CRTIMP_ALTERNATIVE __checkReturn char *  __cdecl strtok_s(__inout_z_opt char * _Str, __in_z const char * _Delim, __deref_inout_z_opt char ** _Context);
#endif
_CRTIMP __checkReturn_wat errno_t __cdecl _strupr_s(__inout_ecount_z(_Size) char * _Str, __in size_t _Size);
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_0(errno_t, _strupr_s, __inout_ecount_z(_Size) char, _String)
__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_0(char *, __RETURN_POLICY_DST, _CRTIMP, _strupr, __inout_z char, _String)
_CRTIMP __checkReturn_wat errno_t __cdecl _strupr_s_l(__inout_ecount_z(_Size) char * _Str, __in size_t _Size, _locale_t _Locale);
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(errno_t, _strupr_s_l, __inout_ecount_z(_Size) char, _String, _locale_t, _Locale)
__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1_EX(char *, __RETURN_POLICY_DST, _CRTIMP, _strupr_l, _strupr_s_l, __inout_z char, _String, __in_opt _locale_t, _Locale)
_CRTIMP __checkReturn_opt size_t  __cdecl strxfrm (__out_z_opt char * _Dst, __in_z const char * _Src, __in size_t _MaxCount);
_CRTIMP __checkReturn_opt size_t  __cdecl _strxfrm_l(__out_z_opt char * _Dst, __in_z const char * _Src, __in size_t _MaxCount, __in_opt _locale_t _Locale);


#ifdef __cplusplus
extern "C++" {
#ifndef _CPP_NARROW_INLINES_DEFINED
#define _CPP_NARROW_INLINES_DEFINED
inline __checkReturn char * __CRTDECL strchr(__in_z char * _Str, __in int _Ch)
{ return (char*)strchr((const char*)_Str, _Ch); }
inline __checkReturn char * __CRTDECL strpbrk(__in_z char * _Str, __in_z const char * _Control)
{ return (char*)strpbrk((const char*)_Str, _Control); }
inline __checkReturn char * __CRTDECL strrchr(__in_z char * _Str, __in int _Ch)
{ return (char*)strrchr((const char*)_Str, _Ch); }
inline __checkReturn char * __CRTDECL strstr(__in_z char * _Str, __in_z const char * _SubStr)
{ return (char*)strstr((const char*)_Str, _SubStr); }
#endif
#ifndef _CPP_MEMCHR_DEFINED
#define _CPP_MEMCHR_DEFINED
inline __checkReturn void * __CRTDECL memchr(__in_bcount_opt(_N) void * _Pv, __in int _C, __in size_t _N)
{ return (void*)memchr((const void*)_Pv, _C, _N); }
#endif
}
#endif


#if     !__STDC__


#if defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC)
#pragma push_macro("strdup")
#undef strdup
#endif


_CRT_NONSTDC_DEPRECATE(_strdup) _CRTIMP __checkReturn char * __cdecl strdup(__in_z_opt const char * _Src);
#if defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC)
#pragma pop_macro("strdup")
#endif


/* prototypes for oldnames.lib functions */
_CRT_NONSTDC_DEPRECATE(_strcmpi) _CRTIMP __checkReturn int __cdecl strcmpi(__in_z const char * _Str1, __in_z const char * _Str2);
_CRT_NONSTDC_DEPRECATE(_stricmp) _CRTIMP __checkReturn int __cdecl stricmp(__in_z const char * _Str1, __in_z const char * _Str2);
_CRT_NONSTDC_DEPRECATE(_strlwr) _CRTIMP char * __cdecl strlwr(__inout_z char * _Str);
_CRT_NONSTDC_DEPRECATE(_strnicmp) _CRTIMP __checkReturn int __cdecl strnicmp(__in_z const char * _Str1, __in_z const char * _Str, __in size_t _MaxCount);
_CRT_NONSTDC_DEPRECATE(_strnset) _CRTIMP char * __cdecl strnset(__inout_z char * _Str, __in int _Val, __in size_t _MaxCount);
_CRT_NONSTDC_DEPRECATE(_strrev) _CRTIMP char * __cdecl strrev(__inout_z char * _Str);
_CRT_NONSTDC_DEPRECATE(_strset)         char * __cdecl strset(__inout_z char * _Str, __in int _Val);
_CRT_NONSTDC_DEPRECATE(_strupr) _CRTIMP char * __cdecl strupr(__inout_z char * _Str);


#endif  /* !__STDC__ */



#ifndef _WSTRING_DEFINED


/* wide function prototypes, also declared in wchar.h  */


#if defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC)
#pragma push_macro("_wcsdup")
#undef _wcsdup
#endif


_CRTIMP __checkReturn wchar_t * __cdecl _wcsdup(__in_z const wchar_t * _Str);


#if defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC)
#pragma pop_macro("_wcsdup")
#endif


#if __STDC_WANT_SECURE_LIB__
_CRTIMP_ALTERNATIVE __checkReturn_wat errno_t __cdecl wcscat_s(__inout_ecount_z(_DstSize) wchar_t * _Dst, __in rsize_t _DstSize, const wchar_t * _Src);
#endif
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(errno_t, wcscat_s, __inout_ecount_z(_Size) wchar_t, _Dest, __in_z const wchar_t *, _Source)
__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1(wchar_t *, __RETURN_POLICY_DST, _CRTIMP, wcscat, __inout_z wchar_t, _Dest, __in_z const wchar_t *, _Source)
_CRTIMP __checkReturn _CONST_RETURN wchar_t * __cdecl wcschr(__in_z const wchar_t * _Str, wchar_t _Ch);
_CRTIMP __checkReturn int __cdecl wcscmp(__in_z const wchar_t * _Str1, __in_z const wchar_t * _Str2);
#if __STDC_WANT_SECURE_LIB__
_CRTIMP_ALTERNATIVE __checkReturn_wat errno_t __cdecl wcscpy_s(__out_ecount_z(_DstSize) wchar_t * _Dst, __in rsize_t _DstSize, __in_z const wchar_t * _Src);
#endif
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(errno_t, wcscpy_s, __out_ecount(_Size) wchar_t, _Dest, __in_z const wchar_t *, _Source)
__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1(wchar_t *, __RETURN_POLICY_DST, _CRTIMP, wcscpy, __out_z wchar_t, _Dest, __in_z const wchar_t *, _Source)
_CRTIMP __checkReturn size_t __cdecl wcscspn(__in_z const wchar_t * _Str, __in_z const wchar_t * _Control);
_CRTIMP __checkReturn size_t __cdecl wcslen(__in_z const wchar_t * _Str);
_CRTIMP __checkReturn size_t __cdecl wcsnlen(__in_ecount_z(_MaxCount) const wchar_t * _Src, __in size_t _MaxCount);
#if __STDC_WANT_SECURE_LIB__ && !defined (__midl)
static __inline __checkReturn size_t __CRTDECL wcsnlen_s(__in_ecount_z(_MaxCount) const wchar_t * _Src, __in size_t _MaxCount)
{
return wcsnlen(_Src, _MaxCount);
}
#endif
#if __STDC_WANT_SECURE_LIB__
_CRTIMP_ALTERNATIVE __checkReturn_wat errno_t __cdecl wcsncat_s(__inout_ecount_z(_DstSize) wchar_t * _Dst, __in rsize_t _DstSize, __in_z const wchar_t * _Src, __in rsize_t _MaxCount);
#endif
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_2(errno_t, wcsncat_s, __inout_ecount_z(_Size) wchar_t, _Dest, __in_z const wchar_t *, _Source, __in size_t, _Count)
__DEFINE_CPP_OVERLOAD_STANDARD_NFUNC_0_2_EX(wchar_t *, __RETURN_POLICY_DST, _CRTIMP, wcsncat, wcsncat_s, __inout_ecount_z(_Count) wchar_t, __inout wchar_t, _Dest, __in_z const wchar_t *, _Source, __in size_t, _Count)
_CRTIMP __checkReturn int __cdecl wcsncmp(__in_z const wchar_t * _Str1, __in_z const wchar_t * _Str2, __in size_t _MaxCount);
#if __STDC_WANT_SECURE_LIB__
_CRTIMP_ALTERNATIVE __checkReturn_wat errno_t __cdecl wcsncpy_s(__out_ecount_z(_DstSize) wchar_t * _Dst, __in rsize_t _DstSize, __in_z const wchar_t * _Src, __in rsize_t _MaxCount);
#endif
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_2(errno_t, wcsncpy_s, __out_ecount(_Size) wchar_t, _Dest, __in_z const wchar_t *, _Source, __in size_t, _Count)
__DEFINE_CPP_OVERLOAD_STANDARD_NFUNC_0_2_EX(wchar_t *, __RETURN_POLICY_DST, _CRTIMP, wcsncpy, wcsncpy_s, __out_z wchar_t, __out_ecount(_Count) wchar_t, _Dest, __in_z const wchar_t *, _Source, __in size_t, _Count)
_CRTIMP __checkReturn _CONST_RETURN wchar_t * __cdecl wcspbrk(__in_z const wchar_t * _Str, __in_z const wchar_t * _Control);
_CRTIMP __checkReturn _CONST_RETURN wchar_t * __cdecl wcsrchr(__in_z const wchar_t * _Str, __in wchar_t _Ch);
_CRTIMP __checkReturn size_t __cdecl wcsspn(__in_z const wchar_t * _Str, __in_z const wchar_t * _Control);
_CRTIMP __checkReturn _CONST_RETURN wchar_t * __cdecl wcsstr(__in_z const wchar_t * _Str, __in_z const wchar_t * _SubStr);
_CRT_INSECURE_DEPRECATE(wcstok_s) _CRTIMP __checkReturn wchar_t * __cdecl wcstok(__inout_z_opt wchar_t * _Str, __in_z const wchar_t * _Delim);
_CRTIMP_ALTERNATIVE __checkReturn wchar_t * __cdecl wcstok_s(__inout_z_opt wchar_t * _Str, __in_z const wchar_t * _Delim, __deref_inout_z_opt wchar_t ** _Context);
_CRT_INSECURE_DEPRECATE(_wcserror_s) _CRTIMP __checkReturn wchar_t * __cdecl _wcserror(__in int _ErrNum);
_CRTIMP __checkReturn_wat errno_t __cdecl _wcserror_s(__out_ecount_z_opt(_SizeInWords) wchar_t * _Buf, __in size_t _SizeInWords, __in int _ErrNum);
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(errno_t, _wcserror_s, __out_ecount(_Size) wchar_t, _Buffer, __in int, _Error)
_CRT_INSECURE_DEPRECATE(__wcserror_s) _CRTIMP __checkReturn wchar_t * __cdecl __wcserror(__in_z_opt const wchar_t * _Str);
_CRTIMP __checkReturn_wat errno_t __cdecl __wcserror_s(__out_ecount_z_opt(_SizeInWords) wchar_t * _Buffer, __in size_t _SizeInWords, __in_z const wchar_t * _ErrMsg);
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(errno_t, __wcserror_s, __out_ecount(_Size) wchar_t, _Buffer, __in_z const wchar_t *, _ErrorMessage)


_CRTIMP __checkReturn int __cdecl _wcsicmp(__in_z const wchar_t * _Str1, __in_z const wchar_t * _Str2);
_CRTIMP __checkReturn int __cdecl _wcsicmp_l(__in_z const wchar_t * _Str1, __in_z const wchar_t * _Str2, __in_opt _locale_t _Locale);
_CRTIMP __checkReturn int __cdecl _wcsnicmp(__in_z const wchar_t * _Str1, __in_z const wchar_t * _Str2, __in size_t _MaxCount);
_CRTIMP __checkReturn int __cdecl _wcsnicmp_l(__in_z const wchar_t * _Str1, __in_z const wchar_t * _Str2, __in size_t _MaxCount, __in_opt _locale_t _Locale);
_CRT_INSECURE_DEPRECATE(_wcsnset_s) _CRTIMP wchar_t * __cdecl _wcsnset(__inout_z wchar_t * _Str, __in_z wchar_t _Val, __in size_t _MaxCount);
_CRTIMP_ALTERNATIVE __checkReturn_wat errno_t __cdecl _wcsnset_s(__inout_ecount_z(_DstSizeInWords) wchar_t * _Dst, __in size_t _DstSizeInWords, wchar_t _Val, __in size_t _MaxCount);
_CRTIMP wchar_t * __cdecl _wcsrev(__inout_z wchar_t * _Str);
_CRT_INSECURE_DEPRECATE(_wcsset_s) _CRTIMP wchar_t * __cdecl _wcsset(__inout_z wchar_t * _Str, wchar_t _Val);
_CRTIMP_ALTERNATIVE __checkReturn_wat errno_t __cdecl _wcsset_s(__inout_ecount_z(_SizeInWords) wchar_t * _Str, __in size_t _SizeInWords, wchar_t _Val);


_CRTIMP __checkReturn_wat errno_t __cdecl _wcslwr_s(__inout_ecount_z(_SizeInWords) wchar_t * _Str, __in size_t _SizeInWords);
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_0(errno_t, _wcslwr_s, __inout_ecount_z(_Size) wchar_t, _String)
__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_0(wchar_t *, __RETURN_POLICY_DST, _CRTIMP, _wcslwr, __inout_z wchar_t, _String)
_CRTIMP __checkReturn_wat errno_t __cdecl _wcslwr_s_l(__inout_ecount_z(_SizeInWords) wchar_t * _Str, __in size_t _SizeInWords, __in_opt _locale_t _Locale);
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(errno_t, _wcslwr_s_l, __inout_ecount_z(_Size) wchar_t, _String, __in_opt _locale_t, _Locale)
__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1_EX(wchar_t *, __RETURN_POLICY_DST, _CRTIMP, _wcslwr_l, _wcslwr_s_l, __inout_z wchar_t, _String, __in_opt _locale_t, _Locale)
_CRTIMP __checkReturn_wat errno_t __cdecl _wcsupr_s(__inout_ecount_z(_Size) wchar_t * _Str, __in size_t _Size);
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_0(errno_t, _wcsupr_s, __inout_ecount_z(_Size) wchar_t, _String)
__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_0(wchar_t *, __RETURN_POLICY_DST, _CRTIMP, _wcsupr, __inout_z wchar_t, _String)
_CRTIMP __checkReturn_wat errno_t __cdecl _wcsupr_s_l(__inout_ecount_z(_Size) wchar_t * _Str, __in size_t _Size, __in_opt _locale_t _Locale);
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_0_1(errno_t, _wcsupr_s_l, __inout_ecount_z(_size) wchar_t, _String, __in_opt _locale_t, _Locale)
__DEFINE_CPP_OVERLOAD_STANDARD_FUNC_0_1_EX(wchar_t *, __RETURN_POLICY_DST, _CRTIMP, _wcsupr_l, _wcsupr_s_l, __inout_z wchar_t, _String, __in_opt _locale_t, _Locale)
_CRTIMP __checkReturn_opt size_t __cdecl wcsxfrm(__out_z_opt wchar_t * _Dst, __in_z const wchar_t * _Src, __in size_t _MaxCount);
_CRTIMP __checkReturn_opt size_t __cdecl _wcsxfrm_l(__out_z_opt wchar_t * _Dst, __in_z const wchar_t *_Src, __in size_t _MaxCount, __in_opt _locale_t _Locale);
_CRTIMP __checkReturn int __cdecl wcscoll(__in_z const wchar_t * _Str1, __in_z const wchar_t * _Str2);
_CRTIMP __checkReturn int __cdecl _wcscoll_l(__in_z const wchar_t * _Str1, __in_z const wchar_t * _Str2, __in_opt _locale_t _Locale);
_CRTIMP __checkReturn int __cdecl _wcsicoll(__in_z const wchar_t * _Str1, __in_z const wchar_t * _Str2);
_CRTIMP __checkReturn int __cdecl _wcsicoll_l(__in_z const wchar_t * _Str1, __in_z const wchar_t *_Str2, __in_opt _locale_t _Locale);
_CRTIMP __checkReturn int __cdecl _wcsncoll(__in_z const wchar_t * _Str1, __in_z const wchar_t * _Str2, __in size_t _MaxCount);
_CRTIMP __checkReturn int __cdecl _wcsncoll_l(__in_z const wchar_t * _Str1, __in_z const wchar_t * _Str2, __in size_t _MaxCount, __in_opt _locale_t _Locale);
_CRTIMP __checkReturn int __cdecl _wcsnicoll(__in_z const wchar_t * _Str1, __in_z const wchar_t * _Str2, __in size_t _MaxCount);
_CRTIMP __checkReturn int __cdecl _wcsnicoll_l(__in_z const wchar_t * _Str1, __in_z const wchar_t * _Str2, __in size_t _MaxCount, __in_opt _locale_t _Locale);


#ifdef  __cplusplus
#ifndef _CPP_WIDE_INLINES_DEFINED
#define _CPP_WIDE_INLINES_DEFINED
extern "C++" {
inline __checkReturn wchar_t * __CRTDECL wcschr(__in_z wchar_t *_Str, wchar_t _Ch)
{return ((wchar_t *)wcschr((const wchar_t *)_Str, _Ch)); }
inline __checkReturn wchar_t * __CRTDECL wcspbrk(__in_z wchar_t *_Str, __in_z const wchar_t *_Control)
{return ((wchar_t *)wcspbrk((const wchar_t *)_Str, _Control)); }
inline __checkReturn wchar_t * __CRTDECL wcsrchr(__in_z wchar_t *_Str, __in wchar_t _Ch)
{return ((wchar_t *)wcsrchr((const wchar_t *)_Str, _Ch)); }
inline __checkReturn wchar_t * __CRTDECL wcsstr(__in_z wchar_t *_Str, __in_z const wchar_t *_SubStr)
{return ((wchar_t *)wcsstr((const wchar_t *)_Str, _SubStr)); }
}
#endif
#endif


#if     !__STDC__


#if defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC)
#pragma push_macro("wcsdup")
#undef wcsdup
#endif


_CRT_NONSTDC_DEPRECATE(_wcsdup) _CRTIMP __checkReturn wchar_t * __cdecl wcsdup(__in_z const wchar_t * _Str);


#if defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC)
#pragma pop_macro("wcsdup")
#endif


/* old names */
#define wcswcs wcsstr


/* prototypes for oldnames.lib functions */
_CRT_NONSTDC_DEPRECATE(_wcsicmp) _CRTIMP __checkReturn int __cdecl wcsicmp(__in_z const wchar_t * _Str1, __in_z const wchar_t * _Str2);
_CRT_NONSTDC_DEPRECATE(_wcsnicmp) _CRTIMP __checkReturn int __cdecl wcsnicmp(__in_z const wchar_t * _Str1, __in_z const wchar_t * _Str2, __in size_t _MaxCount);
_CRT_NONSTDC_DEPRECATE(_wcsnset) _CRTIMP wchar_t * __cdecl wcsnset(__inout_z wchar_t * _Str, __in_z wchar_t _Val, __in size_t _MaxCount);
_CRT_NONSTDC_DEPRECATE(_wcsrev) _CRTIMP wchar_t * __cdecl wcsrev(__inout_z wchar_t * _Str);
_CRT_NONSTDC_DEPRECATE(_wcsset) _CRTIMP wchar_t * __cdecl wcsset(__inout_z wchar_t * _Str, wchar_t _Val);
_CRT_NONSTDC_DEPRECATE(_wcslwr) _CRTIMP wchar_t * __cdecl wcslwr(__inout_z wchar_t * _Str);
_CRT_NONSTDC_DEPRECATE(_wcsupr) _CRTIMP wchar_t * __cdecl wcsupr(__inout_z wchar_t * _Str);
_CRT_NONSTDC_DEPRECATE(_wcsicoll) _CRTIMP __checkReturn int __cdecl wcsicoll(__in_z const wchar_t * _Str1, __in_z const wchar_t * _Str2);


#endif  /* !__STDC__ */


#define _WSTRING_DEFINED
#endif



#ifdef  __cplusplus
}
#endif


#endif  /* _INC_STRING */

ERROR:

1>------ Build started: Project: vss, Configuration: Debug Win32 ------
1>Compiling...
1>mygetopt.c
1>c:\program files\microsoft visual studio 8\vc\include\string.h(205) : error C2375: 'my_strdup' : redefinition; different linkage
1>        d:\latex\include\main.h(147) : see declaration of 'my_strdup'
1>Build log was saved at "file://c:\l2r1\vss\vss\Debug\BuildLog.htm"
1>vss - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Edited 3 Years Ago by pyTony: fixed formatting

As you've given too much of information I have no clue where and what to look for, but I think this must be the problem:
#define strdup my_strdup
Somewhere in mygetopt.c. you must be #including string.h AFTER this #define. So the strdup inside string.h is getting converted (by preprocessor) to my_strdup before it is compiled.
So finally when compiler gets preprocessed version of mygetopt.c it has 2 declaration (and may be definitions) of my_strdup(). I'm sure you'll figure out the rest.

Just 2 more notes:
1. typedef int bool; => NOT NICE. NOT NICE AT ALL.
2. Next time use the attachements instead of pasting so many lines of code. Sorry to say but it's simply unreadable.

I'm sure someone intetionally wrote that "#define strdup..." to solve some problem hopefully..
Talk to that fellow and ask him what was he thinking.. ?

jdo not use the string.h file that was included in the download -- it probably doesn't work with the Microsoft compiler. Microsoft has its own version of string.h that you should be using. Just delete string.h from your project directory and remove it from solution view.

Second, please do not post so much code, zip it up into a file and attach it to your program.

This article has been dead for over six months. Start a new discussion instead.