SDC C-Project CF Review 프로그램
LYW
2021-10-15 07a62310a7480610663ffc608491cf46370d99b8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/***************************************************************************
 
  Title:    download.h
 
  Version:  1.00
 
  Date:   12/05/1995
 
  Author(s):  Dennis Smith
 
  Header for Download function for PMAC Communications Library.
 
  Note(s):
 
----------------------------------------------------------------------------
 
  Change log:
 
    Date     Rev   Who      Description
  --------- ----- ----- --------------------------------------------
 
  05Dec95         DS    created file
***************************************************************************/
 
#if !defined( _DOWNLOAD_H )
  #define _DOWNLOAD_H
 
  #include "common.h"
  #include <stdio.h>
 
  #define MAXKEYSIZE    32
  #define MAXMACROSIZE  128
  #define MAXWORDSIZE   32
  #define MAXTEXTSIZE   81
  #define MAXNESTDEPTH  10
  #define MAXPARAMETERS 5
  #define MAXINCLUDE    10
 
  #ifdef __cplusplus
extern "C" {
  #endif
 
typedef struct tagMacro {
  long line;
  char *key, *macro;
  struct tagMacro *left, *right;
} MACRO, *PMACRO;
 
typedef void (FAR WINAPI * DOWNLOADMSGPROC) 
  ( LPSTR str, BOOL newline );
 
typedef int  (FAR WINAPI * DOWNLOADGETPROC) 
  ( int nIndex, LPSTR lpszBuffer, int nMaxLength );
 
typedef void (FAR WINAPI * DOWNLOADPROGRESS) 
  ( int nPercent );
 
typedef void (FAR WINAPI * DOWNLOADERRORPROC) 
  ( LPSTR fname, LONG err, LONG line, LPSTR szLine );
 
 
 
// Globals *******************************************************************
typedef struct tagDownload {
 
  ULONG     TotalLines;
  UINT      TotalWarnings;
  UINT      TotalErrors;
  UINT      TotalMessages;
  BOOL      bMacro, bMap, bLog, bDnld, bTable;
  ULONG     hThread;
  BOOL      bThreadRunning;
  BOOL      bAbortThread;
  BOOL      bCompileError;
  BOOL      bDoChecksums;
  DWORD     dwDevice;
  DWORD     iTimeout;
  DWORD     dwEnum;
  LOCATIONTYPE location;
 
  PMACRO    macroTable;
  PMACRO    keyTable;
  PMACRO    messages;
  char      fileName[MAX_PATH ]; // original input path
  char      mapName[MAX_PATH ];  // map file name
  char      msgName[MAX_PATH ];  // message/log file name
  char      tblName[MAX_PATH ];  // label table file name
  char      outName[MAX_PATH ];  // output file name
  char      plccName[MAX_PATH ]; // binary plc output file name
 
  DOWNLOADMSGPROC   messageProc; // Pointer to a message callback function
  DOWNLOADGETPROC   getlineProc; // Pointer to a getline callback function
  DOWNLOADPROGRESS  progressProc;// Pointer to a progress callback function
  DOWNLOADERRORPROC errorProc;   // Pointer to a error reporting callback
 
  BOOL      bInComment;             // inside comment section
  int       Warnings;
  int       Errors;
  int       Include;                // != 0 currently getting input from file
  char *inName[MAXINCLUDE ];        // current include input file name
  UINT      inLine[MAXINCLUDE];     // current line number
  FILE *inFile[MAXINCLUDE];         // current input file for includes
  long      inFileLen[MAXINCLUDE ]; // length of file in bytes
  long      inFilePos[MAXINCLUDE ]; // current pos in file
  int       inErrors[MAXINCLUDE ];
  int       inWarnings[MAXINCLUDE ];
  UINT      IfNestDepth;
  BOOL      IfStack[MAXNESTDEPTH];
 
} DOWNLOAD, *PDOWNLOAD;
 
// Functions --------------------------------------------------------------
 
  // Exported functions
  int  CALLBACK PmacDownloadExA(DWORD dwDevice, DOWNLOADMSGPROC msgp, DOWNLOADGETPROC getp,
                                DOWNLOADPROGRESS prgp,DOWNLOADERRORPROC errp,PCHAR filename,
                                BOOL macro, BOOL map,BOOL log, BOOL dnld );
  int  CALLBACK PmacDownloadA( DWORD dwDevice, DOWNLOADMSGPROC msgp, DOWNLOADGETPROC getp,
                               DOWNLOADPROGRESS pprg, PCHAR filename, BOOL macro, BOOL map, BOOL log, BOOL dnld );
  int  CALLBACK PmacDownloadExW(DWORD dwDevice, DOWNLOADMSGPROC msgp, DOWNLOADGETPROC getp,
                                DOWNLOADPROGRESS prgp,DOWNLOADERRORPROC errp,PWCHAR filename,
                                BOOL macro, BOOL map,BOOL log, BOOL dnld );
  int  CALLBACK PmacDownloadW( DWORD dwDevice, DOWNLOADMSGPROC msgp, DOWNLOADGETPROC getp,
                               DOWNLOADPROGRESS pprg, PWCHAR fname, BOOL macro, BOOL map, BOOL log, BOOL dnld );
  int  CALLBACK PmacThreadDownloadExA( DWORD dwDevice, DOWNLOADMSGPROC msgp, DOWNLOADGETPROC getp,
                            DOWNLOADPROGRESS prgp,DOWNLOADERRORPROC errp, PCHAR filename, BOOL macro, BOOL map,
                            BOOL log, BOOL dnld );
  int  CALLBACK PmacThreadDownloadA( DWORD dwDevice, DOWNLOADMSGPROC msgp, DOWNLOADGETPROC getp,
                               DOWNLOADPROGRESS pprg, PCHAR filename, BOOL macro, BOOL map, BOOL log, BOOL dnld );
  int  CALLBACK PmacThreadDownloadExW( DWORD dwDevice, DOWNLOADMSGPROC msgp, DOWNLOADGETPROC getp,
                            DOWNLOADPROGRESS prgp,DOWNLOADERRORPROC errp, PWCHAR filename, BOOL macro, BOOL map,
                            BOOL log, BOOL dnld );
  int  CALLBACK PmacThreadDownloadW( DWORD dwDevice, DOWNLOADMSGPROC msgp, DOWNLOADGETPROC getp,
                               DOWNLOADPROGRESS pprg, PWCHAR fname, BOOL macro, BOOL map, BOOL log, BOOL dnld );
  void CALLBACK PmacDownloadFile( DWORD dwDevice, char *fname );
  BOOL CALLBACK PmacCompilePLCC( DWORD dwDevice, char *plccName, char *outName );
  BOOL CALLBACK WriteDictionary( const char *tblName, PMACRO * root );
  BOOL CALLBACK ReadDictionary( const char *tblName, PMACRO * root );
  int  CALLBACK PmacDownloadFirmwareFile( DWORD dwDevice, DOWNLOADMSGPROC msgp, DOWNLOADPROGRESS prgp, LPCTSTR filename );
  void CALLBACK PmacAbortDownload( DWORD dwDevice );
  void CALLBACK PmacSetMaxDownloadErrors( UINT max );
  void CALLBACK AddDownloadError( LPSTR fname, LONG err, LONG line, LPSTR szLine );
 
  // Internal functions NOT EXPORTED
  void  _cdecl DownloadThread( PVOID filename );
  void  _cdecl DownloadFirmwareThread( PVOID filename );
  void  CheckAndReportErrors( DWORD dwDevice, DWORD line, char *instr );
  void  AddError( LPSTR err, LONG line );
  void  AddWarning( LPSTR warn, LONG line );
  void  AddMessage( LPSTR msg );
  void  SetPredefinedMacros( DWORD dwDevice );
  BOOL  StoreMacro( char *key, char *macro );
  BOOL  PreProcess( DWORD dwDevice, char *inname, char *outName );
  BOOL  ReadLine( PTCHAR ln, UINT maxchr );
  BOOL  CloseInclude( void );
  BOOL  OpenInclude( char *filename );
  UINT  ParseFilename( const char *inStr, char *outStr, UINT maxchar );
  UINT  ParseKeyWord( const char *inStr, char *outStr, UINT maxchar );
  UINT  ParseMacro( const char *inStr, char *outStr, UINT maxchar );
  BOOL  ParseLine( const char *inStr, char *outStr, UINT maxchar );
  int   ParseParameters( char *src, int *pcount, char *param[] );
  int   Function( char *dest, char *src, char **ep );
  BOOL  WriteMap( char *mapName, char *inname );
  BOOL  WriteMessages( char *msgName, char *inname );
 
  // Macro table specific
  PMACRO SearchForKey( PMACRO root, char *key );
  void   Flush( PMACRO * root );
  PMACRO DeleteByKey( PMACRO root, char *key );
  PMACRO AddMacro(PMACRO root,PMACRO r,char *k,char *m,long l, BOOL no_duplicates );
  PMACRO StoreByLine( PMACRO root, PMACRO r, char *k, char *m, long l );
  void   fPrintKey( PMACRO root, FILE * fptr );
  void   PrintKey( PMACRO root, FILE * fptr );
 
  #ifdef __cplusplus
}
  #endif
 
  #ifdef UNICODE
    #define PmacDownload PmacDownloadW
  #else
    #define PmacDownload PmacDownloadA
  #endif // !UNICODE
 
#endif