Commit a2280b1e authored by Christoffer Ackelman's avatar Christoffer Ackelman

Removed dependency on flex.

parent a7b6f740
...@@ -8,7 +8,7 @@ Install the following packages ...@@ -8,7 +8,7 @@ Install the following packages
Mandatory: Mandatory:
> apt-get install doxygen flex gcc g++ make libasound2-dev libdb5.3-dev libdb5.3++-dev > apt-get install doxygen gcc g++ make libasound2-dev libdb5.3-dev libdb5.3++-dev
Optional: Optional:
......
...@@ -27,10 +27,6 @@ $(obj_dir)/%.o : $(obj_dir)/%.cmsg ...@@ -27,10 +27,6 @@ $(obj_dir)/%.o : $(obj_dir)/%.cmsg
@ $(tools_cmsg2c) -b $(comp_name) $(source) $(tmp_dir)/$(sname).c @ $(tools_cmsg2c) -b $(comp_name) $(source) $(tmp_dir)/$(sname).c
@ $(cc) $(cflags) $(csetos) $(cinc) $(cobj) $(tmp_dir)/$(sname).c @ $(cc) $(cflags) $(csetos) $(cinc) $(cobj) $(tmp_dir)/$(sname).c
$(bld_dir)/%.c : %.l
@ $(log_l_obj)
@ $(lex) -o$(bld_dir)/$(sname).c $(source)
%.o : %.c %.o : %.c
@ echo "Warning, rule shall normally not be used: %.o : %.c" @ echo "Warning, rule shall normally not be used: %.o : %.c"
ifeq ($(nodep),) ifeq ($(nodep),)
......
...@@ -98,7 +98,6 @@ cp := cp ...@@ -98,7 +98,6 @@ cp := cp
cpflags := cpflags :=
arflags := r arflags := r
obj := -c -o $(target) obj := -c -o $(target)
lex := flex
javac := javac javac := javac
ifdef pwre_ar ifdef pwre_ar
ar := $(pwre_ar) ar := $(pwre_ar)
...@@ -160,8 +159,6 @@ domap = -Xlinker -Map -Xlinker $(map) ...@@ -160,8 +159,6 @@ domap = -Xlinker -Map -Xlinker $(map)
log_h_h = echo "Exporting $<" log_h_h = echo "Exporting $<"
log_x_h = echo "Exporting $< to $(notdir $@)" log_x_h = echo "Exporting $< to $(notdir $@)"
log_l_obj = echo "Compiling $<"
log_l_lib = echo "Compiling $(notdir $(basename $@))($<)"
#log_c_d = echo "Updating dependencies $<" #log_c_d = echo "Updating dependencies $<"
log_c_obj = echo "Compiling $<" log_c_obj = echo "Compiling $<"
log_c_lib = echo "Compiling $(notdir $(basename $@))($<)" log_c_lib = echo "Compiling $(notdir $(basename $@))($<)"
......
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2019 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* 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 ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
#ifndef cmsg2c_h
#define cmsg2c_h
void lex_FacName(char* FacName);
void lex_FacNum(int FacNum);
#endif
%{
#include <stdio.h>
#include <stdlib.h>
#include "pwr_msg.h"
#include "cmsg2c.h"
int lineno = 0;
#undef ECHO
#define ECHO
%}
ws [ \t]+
nl \n
comment !.*
%option nounput
%option noinput
%x facnam facnum
%%
{ws} ;
{comment} ;
{nl} lineno++;
msg_sFacility {BEGIN(facnam);}
<facnam>[A-Z0-9$_]+facility {BEGIN(facnum); lex_FacName((char *)yytext);}
<facnum>[0-9]+ {BEGIN(0); lex_FacNum(atoi((char *)yytext));}
%%
ifndef link_rule_mk ifndef link_rule_mk
link_rule_mk := 1 link_rule_mk := 1
link = $(ld) $(linkflags) $(domap) -o $(export_exe) $(export_obj) $(objects) $(pwre_conf_libdir) $(pwre_conf_lib) -lfl link = $(ld) $(linkflags) $(domap) -o $(export_exe) $(export_obj) $(objects) $(pwre_conf_libdir) $(pwre_conf_lib)
endif endif
...@@ -35,22 +35,12 @@ ...@@ -35,22 +35,12 @@
*/ */
/* /*
* Filename: * Creates a .c-file from a .cmsg file
* tools_cmsg2c.c *
* * The -b branch flag must be set if you want to generate messages for PROVIEW.
* Revision history: */
* Rev Edit Date Who Comment
* ------- ---- ---------- ---- -------
* X0.1 1 1996-10-01 ML Created
*
* Description: Creates a .c-file from a file which contains all c_msg-files
* for which messages should be generated.
* The c_msg-file should contain all
*
* The -b branch flag must be set if you wan't to generate messages
* for PROVIEW.
*/
#include <ctype.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
...@@ -58,9 +48,7 @@ ...@@ -58,9 +48,7 @@
#include "pwr_lst.h" #include "pwr_lst.h"
#include "pwr_msg.h" #include "pwr_msg.h"
#include "cmsg2c.h" #define MSG_NEW_STRING(str) strncpy(malloc(strlen(str) + 1), str, strlen(str) + 1)
#define MSG_NEW_STRING(str) strcpy(malloc(strlen(str) + 1), str)
typedef struct s_FacilityCB sFacilityCB; typedef struct s_FacilityCB sFacilityCB;
...@@ -70,83 +58,17 @@ struct s_FacilityCB { ...@@ -70,83 +58,17 @@ struct s_FacilityCB {
int facnum; int facnum;
}; };
extern int lineno; static char* inFile;
static int SyntaxError;
static struct LstHead lFacH; static struct LstHead lFacH;
static sFacilityCB* CurrFac = NULL; static sFacilityCB* CurrFac = NULL;
static void CopyFile(FILE* ifp, FILE* ofp);
static void WriteFacility(FILE* cfp, char* branch);
static void WriteIncludes(FILE* cfp);
static void usage() static void usage()
{ {
printf("Usage: tools_cmsg2c [-b branch] input_file output_file\n"); printf("Usage: tools_cmsg2c [-b branch] input_file output_file\n");
exit(1); exit(1);
} }
int main(int argc, char** argv)
{
extern FILE* yyin;
extern int yylex();
FILE* cfp = NULL;
int bmsg = 0;
char* branch = NULL;
int inFile;
int outFile;
if (argc < 3)
usage();
if (argv[1][0] == '-') {
if (argv[1][1] == 'b') {
branch = argv[2];
bmsg = 1;
} else
usage();
if (argc != 5)
usage();
} else if (argc != 3)
usage();
inFile = bmsg ? 3 : 1;
outFile = inFile + 1;
if (!(yyin = fopen(argv[inFile], "r"))) {
printf("Can't open input file: %s", argv[inFile]);
exit(1);
}
LstInit(&lFacH);
SyntaxError = 0;
lineno = 1;
yylex();
if (!SyntaxError) {
if (!(cfp = fopen(argv[outFile], "w+"))) {
printf("Can't open output file: %s", argv[outFile]);
exit(1);
}
rewind(yyin);
WriteIncludes(cfp);
CopyFile(yyin, cfp);
WriteFacility(cfp, branch);
}
fclose(yyin);
fclose(cfp);
exit(EXIT_SUCCESS);
}
/*
* Routines called by lex
*/
void lex_FacName(char* facnam) void lex_FacName(char* facnam)
{ {
sFacilityCB* facp = (sFacilityCB*)calloc(1, sizeof(sFacilityCB)); sFacilityCB* facp = (sFacilityCB*)calloc(1, sizeof(sFacilityCB));
...@@ -176,14 +98,42 @@ void lex_FacNum(int facnum) ...@@ -176,14 +98,42 @@ void lex_FacNum(int facnum)
CurrFac = NULL; CurrFac = NULL;
} }
/* static void lex(FILE* fp) {
* Local routines char buffer[500];
*/ int next_is_facnum = 0;
int lineno = 1;
while (fgets(buffer, 500, fp) != NULL) {
if (strstr(buffer, "msg_sFacility")) {
char* facnam = strstr(buffer, "msg_sFacility") + 14; // "MYfacility[] = "
facnam[strchr(facnam, '[')-facnam] = '\0'; // "MYfacility"
if (!strstr(facnam, "facility")) {
fprintf(stderr, "Syntax error in file %s line %d\n", inFile, lineno);
exit(1);
}
lex_FacName(facnam);
next_is_facnum = 1;
} else if (next_is_facnum) {
char *line = buffer;
while (!isdigit(line[0])) {
line++; // "1337,"
}
line[strchr(line, ',')-line] = '\0';
char* end;
int facnum = strtol(line, &end, 10);
if (!facnum) {
fprintf(stderr, "Syntax error in file %s line %d\n", inFile, lineno);
exit(1);
}
lex_FacNum(facnum);
next_is_facnum = 0;
}
lineno++;
}
}
static void CopyFile(FILE* ifp, FILE* ofp) static void CopyFile(FILE* ifp, FILE* ofp)
{ {
int c; int c;
while ((c = getc(ifp)) != EOF) while ((c = getc(ifp)) != EOF)
putc(c, ofp); putc(c, ofp);
} }
...@@ -210,7 +160,53 @@ static void WriteFacility(FILE* cfp, char* branch) ...@@ -210,7 +160,53 @@ static void WriteFacility(FILE* cfp, char* branch)
branch ? branch : "pwrp"); branch ? branch : "pwrp");
} }
static void WriteIncludes(FILE* cfp) int main(int argc, char** argv)
{ {
FILE* in;
FILE* cfp = NULL;
int bmsg = 0;
char* branch = NULL;
char* outFile;
if (argc < 3)
usage();
if (argv[1][0] == '-') {
if (argv[1][1] == 'b') {
branch = argv[2];
bmsg = 1;
} else
usage();
if (argc != 5)
usage();
} else if (argc != 3)
usage();
inFile = bmsg ? argv[3] : argv[1];
outFile = bmsg ? argv[4] : argv[2];
if (!(in = fopen(inFile, "r"))) {
printf("Can't open input file: %s", inFile);
exit(1);
}
LstInit(&lFacH);
lex(in);
if (!(cfp = fopen(outFile, "w+"))) {
printf("Can't open output file: %s", outFile);
fclose(in);
exit(1);
}
rewind(in);
fprintf(cfp, "#include \"pwr_msg.h\"\n\n"); fprintf(cfp, "#include \"pwr_msg.h\"\n\n");
} CopyFile(in, cfp);
WriteFacility(cfp, branch);
fclose(in);
fclose(cfp);
return 0;
}
\ No newline at end of file
ifndef link_rule_mk ifndef link_rule_mk
link_rule_mk := 1 link_rule_mk := 1
link = $(ld) $(linkflags) $(domap) -o $(export_exe) $(export_obj) $(objects) $(pwre_conf_libdir) $(pwre_conf_lib) -lfl link = $(ld) $(linkflags) $(domap) -o $(export_exe) $(export_obj) $(objects) $(pwre_conf_libdir) $(pwre_conf_lib)
endif endif
/*
* ProviewR Open Source Process Control.
* Copyright (C) 2005-2019 SSAB EMEA AB.
*
* This file is part of ProviewR.
*
* 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 ProviewR. If not, see <http://www.gnu.org/licenses/>
*
* Linking ProviewR statically or dynamically with other modules is
* making a combined work based on ProviewR. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* ProviewR give you permission to, from the build function in the
* ProviewR Configurator, combine ProviewR with modules generated by the
* ProviewR PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of ProviewR (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
#ifndef co_msg2cmsg_h
#define co_msg2cmsg_h
void lex_FacName(const char* Facnam);
void lex_FacNum(int Facnum);
void lex_FacPrefix(const char* Prefix);
void lex_MsgName(const char* Name);
void lex_MsgText(const char* Text);
void lex_MsgSeverity(msg_eSeverity Severity);
void lex_LexError(int Lineno, char* Str);
#endif
%{
#include <stdio.h>
#include <stdlib.h>
#include "pwr_msg.h"
#include "msg2cmsg.h"
int lineno = 0;
#undef ECHO
#define ECHO
%}
ws [ \t]+
nl \n
comment !.*
%option nounput
%option noinput
%x facnam faccom facnum prefix prefixstr prefixstr_nl msgnam msgtxt msgsev
%%
{ws} ;
{comment} ;
{nl} lineno++;
\.facility {BEGIN(facnam);}
<facnam>{comment} ;
<facnam>[A-Z0-9$_]+ {BEGIN(faccom); lex_FacName((char *)yytext);};
<facnam>{nl} {printf("No facility name given!\n"); exit(1);}
<faccom>[ \t]*,[ \t]* {BEGIN(facnum);}
<faccom>{nl} {printf("No facility number given!\n"); exit(1);}
<facnum>[0-9]+ {BEGIN(prefix); lex_FacNum(atoi((char *)yytext));}
<facnum>{nl} {printf("No facility number given!\n"); exit(1);}
<prefix>{comment} {BEGIN(msgnam); printf("Default prefix\n");}
<prefix>{nl} {BEGIN(msgnam); printf("Default prefix\n");}
<prefix>\/prefix[ \t]*=[ \t]* {BEGIN(prefixstr);}
<prefixstr>{comment} ;
<prefixstr>[A-Z0-9$_]+ {BEGIN(prefixstr_nl); lex_FacPrefix((char *)yytext);}
<prefixstr>{nl} {printf("No prefix string given!\n"); exit(1);}
<prefixstr_nl>\n {BEGIN(msgnam);}
<msgnam>{comment} ;
<msgnam>[A-Za-z0-9$_]+ {BEGIN(msgtxt); lex_MsgName((char *)yytext);}
<msgnam>\.facility {BEGIN(facnam);}
<msgnam>\.end {BEGIN(0);}
<msgtxt>\<.*\> {BEGIN(msgsev); lex_MsgText((char *)yytext);}
<msgsev>{comment} {printf("Comment: no severity given"); exit(1);}
<msgsev>\n {printf("New line: no severity given"); exit(1);}
<msgsev>\/w.*\n {BEGIN(msgnam); lineno++; lex_MsgSeverity(msg_eSeverity_Warning);}
<msgsev>\/s.*\n {BEGIN(msgnam); lineno++; lex_MsgSeverity(msg_eSeverity_Success);}
<msgsev>\/e.*\n {BEGIN(msgnam); lineno++; lex_MsgSeverity(msg_eSeverity_Error);}
<msgsev>\/i.*\n {BEGIN(msgnam); lineno++; lex_MsgSeverity(msg_eSeverity_Info);}
<msgsev>\/f.*\n {BEGIN(msgnam); lineno++; lex_MsgSeverity(msg_eSeverity_Fatal);}
%%
...@@ -35,16 +35,8 @@ ...@@ -35,16 +35,8 @@
*/ */
/* /*
* Filename: * Creates a .cmsg file and a .h file from a .msg-file
* tools_msg2cmsg.c */
*
* Revision history:
* Rev Edit Date Who Comment
* ------- ---- ---------- ---- -------
* X0.1 1 1996-10-01 ML Created
*
* Description: Creates a .c_msg-file and a .h-file from a .msg-file
*/
#include <ctype.h> #include <ctype.h>
#include <stdio.h> #include <stdio.h>
...@@ -53,10 +45,8 @@ ...@@ -53,10 +45,8 @@
#include "pwr_lst.h" #include "pwr_lst.h"
#include "pwr_msg.h" #include "pwr_msg.h"
#include "msg2cmsg.h"
#define MSG_NEW_STRING(str) \ #define MSG_NEW_STRING(str) strncpy(malloc(strlen(str) + 1), str, strlen(str) + 1)
strncpy(malloc(strlen(str) + 1), str, strlen(str) + 1)
typedef struct s_FacilityCB sFacilityCB; typedef struct s_FacilityCB sFacilityCB;
typedef struct s_MsgCB sMsgCB; typedef struct s_MsgCB sMsgCB;
...@@ -73,86 +63,10 @@ struct s_FacilityCB { ...@@ -73,86 +63,10 @@ struct s_FacilityCB {
msg_sFacility f; msg_sFacility f;
}; };
/* defined by lexyy.c */ static char* inFile;
extern int lineno;
static int SyntaxError;
static struct LstHead lFacH; static struct LstHead lFacH;
/*
* Local functions
*/
static void WriteFiles(char* fname, FILE* cfp, FILE* hfp);
static void TranslateFormatSpec(const char* msgstr, char** transstr);
/*
* Main
*/
int main(int argc, char** argv)
{
extern FILE* yyin;
extern int yylex();
FILE* cfp = NULL;
FILE* hfp = NULL;
if (argc != 4) {
printf("Usage: co_msg2cmsg msg-file c_msg-file h_file\n");
exit(2);
}
if (!(yyin = fopen(argv[1], "r"))) {
printf("Can't open input file: %s\n", argv[1]);
exit(2);
}
if (!(cfp = fopen(argv[2], "w"))) {
printf("Can't open c_msg-output file: %s\n", argv[2]);
fclose(yyin);
exit(2);
}
if (!(hfp = fopen(argv[3], "w"))) {
printf("Can't open h-output file: %s\n", argv[3]);
fclose(yyin);
fclose(cfp);
exit(2);
}
LstInit(&lFacH);
SyntaxError = 0;
lineno = 1;
yylex();
if (!SyntaxError) {
char fname[256];
char* p;
if ((p = strrchr(argv[2], '/')))
strncpy(fname, p + 1, sizeof(fname));
else
strncpy(fname, argv[2], sizeof(fname));
if ((p = strchr(fname, '.')))
*p = '\0';
WriteFiles(fname, cfp, hfp);
}
fclose(yyin);
fclose(cfp);
fclose(hfp);
exit(EXIT_SUCCESS);
}
/*
* Routines which are called by lexyy.c
*/
void lex_FacName(const char* FacName) void lex_FacName(const char* FacName)
{ {
sFacilityCB* facp = (sFacilityCB*)calloc(1, sizeof(sFacilityCB)); sFacilityCB* facp = (sFacilityCB*)calloc(1, sizeof(sFacilityCB));
...@@ -170,16 +84,18 @@ void lex_FacNum(int FacNum) ...@@ -170,16 +84,18 @@ void lex_FacNum(int FacNum)
void lex_FacPrefix(const char* Prefix) void lex_FacPrefix(const char* Prefix)
{ {
LstEntry(lFacH.prev, sFacilityCB, FacL)->f.Prefix = MSG_NEW_STRING(Prefix); char *str = strncpy(malloc(strlen(Prefix) + 3), Prefix, strlen(Prefix)+1);
strcat(str, "__\0");
LstEntry(lFacH.prev, sFacilityCB, FacL)->f.Prefix = str;
} }
void lex_MsgName(const char* MsgName) void lex_MsgName(const char* MsgName)
{ {
sMsgCB* msgp = (sMsgCB*)calloc(1, sizeof(sMsgCB)); sMsgCB* msgp = (sMsgCB*)calloc(1, sizeof(sMsgCB));
int i;
int len = strlen(MsgName); int len = strlen(MsgName);
msgp->m.MsgName = malloc(len + 1); msgp->m.MsgName = malloc(len + 1);
int i;
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
msgp->m.MsgName[i] = toupper(MsgName[i]); msgp->m.MsgName[i] = toupper(MsgName[i]);
msgp->m.MsgName[i] = '\0'; msgp->m.MsgName[i] = '\0';
...@@ -187,6 +103,37 @@ void lex_MsgName(const char* MsgName) ...@@ -187,6 +103,37 @@ void lex_MsgName(const char* MsgName)
LstInsert(&LstEntry(lFacH.prev, sFacilityCB, FacL)->MsgH, &msgp->MsgL); LstInsert(&LstEntry(lFacH.prev, sFacilityCB, FacL)->MsgH, &msgp->MsgL);
} }
static void TranslateFormatSpec(const char* msgstr, char** transstr)
{
char* l;
const char* m = msgstr;
int extra = 0;
int len = 0;
/* '"' will be substituted with '\"', allocate space for it */
while (*m) {
if (*m == '"')
extra++;
m++;
len++;
}
*transstr = (char*)malloc(len + extra + 1);
l = *transstr;
m = msgstr;
while (*m != '\0') {
if (*m == '"') {
*l++ = '\\';
*l++ = '"';
} else {
*l++ = *m;
}
m++;
}
*l = '\0';
}
void lex_MsgText(const char* Text) void lex_MsgText(const char* Text)
{ {
struct LstHead* ml = LstEntry(lFacH.prev, sFacilityCB, FacL)->MsgH.prev; struct LstHead* ml = LstEntry(lFacH.prev, sFacilityCB, FacL)->MsgH.prev;
...@@ -201,15 +148,77 @@ void lex_MsgSeverity(msg_eSeverity Severity) ...@@ -201,15 +148,77 @@ void lex_MsgSeverity(msg_eSeverity Severity)
LstEntry(ml, sMsgCB, MsgL)->Severity = Severity; LstEntry(ml, sMsgCB, MsgL)->Severity = Severity;
} }
void lex_LexError(int Lineno, char* Str) static void lex(FILE* fp) {
{ char buffer[500];
printf("LexError: line %d, '%s'\n", Lineno, Str); int lineno = 1;
SyntaxError = 1; while (fgets(buffer, 500, fp) != NULL) {
if (strstr(buffer, ".facility")) {
char *line = strstr(buffer, ".facility") + 10;
while (isspace(line[0])) {
line++;
}
char *facnam = line; // "ASD,123 "
char *facnum0 = strchr(line, ',')+1; // "123 "
facnam[strchr(facnam, ',')-facnam] = '\0'; // "ASD"
char* tmp = facnum0;
while (isdigit(tmp[0])) {
tmp++;
}
facnum0[tmp-facnum0] = '\0';
tmp = NULL;
int facnum = strtol(facnum0, &tmp, 10);
if (!facnum) {
fprintf(stderr, "Syntax error in file %s line %d\n", inFile, lineno);
exit(1);
}
lex_FacName(facnam);
lex_FacNum(facnum);
lex_FacPrefix(facnam);
} else if (isalnum(buffer[0])) { // "mymsg <my message text> /error"
char *msgname = buffer; // msgname = "mymsg <my message text> /error"
char *tmp = msgname;
while (isalnum(tmp[0]) || tmp[0] == '_') {
tmp++;
}
tmp[0] = '\0'; // msgname = "mymsg"
tmp++;
while (tmp[0] != '<') {
tmp++;
}
tmp++;
char* msgtxt = tmp; // msgtxt = "my message text> /error"
while (tmp[0] != '>') {
tmp++;
}
tmp[0] = '\0'; // msgtxt = "my message text"
tmp++;
char *msgseverity = tmp; // " /error"
while (isspace(msgseverity[0])) {
msgseverity++; // "/error"
}
lex_MsgName(msgname);
lex_MsgText(msgtxt);
if (msgseverity[1] == 'w') {
lex_MsgSeverity(msg_eSeverity_Warning);
} else if (msgseverity[1] == 's') {
lex_MsgSeverity(msg_eSeverity_Success);
} else if (msgseverity[1] == 'e') {
lex_MsgSeverity(msg_eSeverity_Error);
} else if (msgseverity[1] == 'i') {
lex_MsgSeverity(msg_eSeverity_Info);
} else if (msgseverity[1] == 'f') {
lex_MsgSeverity(msg_eSeverity_Fatal);
} else {
fprintf(stderr, "Syntax error in file %s line %d\n", inFile, lineno);
exit(1);
}
}
lineno++;
}
} }
/*
* Local routines
*/
static void WriteFiles(char* fname, FILE* cfp, FILE* hfp) static void WriteFiles(char* fname, FILE* cfp, FILE* hfp)
{ {
struct LstHead * fl; struct LstHead * fl;
...@@ -262,61 +271,54 @@ static void WriteFiles(char* fname, FILE* cfp, FILE* hfp) ...@@ -262,61 +271,54 @@ static void WriteFiles(char* fname, FILE* cfp, FILE* hfp)
fprintf(hfp, "\n#endif\n"); fprintf(hfp, "\n#endif\n");
} }
/* int main(int argc, char** argv)
* TranslateFormatSpec
*
* search the msgstr and replace any occurance of VMS-like specifiers
* (!AF !UL !XL, are replaced by %s %u %x)
*
*/
static void TranslateFormatSpec(const char* msgstr, char** transstr)
{ {
char* l; FILE* cfp = NULL;
const char* m = msgstr + 1; /* Skip '<' */ FILE* hfp = NULL;
int extra = 0; FILE* in = NULL;
int len = 0;
/* '"' will be substituted with '\"', allocate space for it */ if (argc != 4) {
while (*m) { printf("Usage: co_msg2cmsg msg-file c_msg-file h_file\n");
if (*m == '"') exit(2);
extra++;
m++;
len++;
} }
*transstr = (char*)malloc(len + extra + 1); inFile = argv[1];
l = *transstr; if (!(in = fopen(inFile, "r"))) {
m = msgstr + 1; /* Skip '<' */ printf("Can't open input file: %s\n", inFile);
exit(2);
}
while (*m != '\0') { if (!(cfp = fopen(argv[2], "w"))) {
if (*m == '"') { printf("Can't open c_msg-output file: %s\n", argv[2]);
*l++ = '\\'; fclose(in);
*l++ = '"'; exit(2);
m++; }
} else if (*m++ == '!') {
/* if (!(hfp = fopen(argv[3], "w"))) {
* could be a format spec, if so we also skip '!' printf("Can't open h-output file: %s\n", argv[3]);
*/ fclose(in);
if (*m == 'A' && *(m + 1) == 'F') { fclose(cfp);
*l++ = '%'; exit(2);
m++;
*l++ = 's';
m++;
} else if (*m == 'U' && *(m + 1) == 'L') {
*l++ = '%';
m++;
*l++ = 'u';
m++;
} else if (*m == 'X' && *(m + 1) == 'L') {
*l++ = '%';
m++;
*l++ = 'x';
m++;
} else
*l++ = '!'; /* nope, put back the '!' */
} else /* just copy */
*l++ = *(m - 1);
} }
*(l - 1) = '\0'; /* Skip '>' */
LstInit(&lFacH);
lex(in);
char fname[256];
char* p = NULL;
if ((p = strrchr(argv[2], '/')))
strncpy(fname, p + 1, sizeof(fname));
else
strncpy(fname, argv[2], sizeof(fname));
if ((p = strchr(fname, '.')))
*p = '\0';
WriteFiles(fname, cfp, hfp);
fclose(in);
fclose(cfp);
fclose(hfp);
return 0;
} }
...@@ -421,7 +421,6 @@ else ...@@ -421,7 +421,6 @@ else
pwre_config_check_lib libz LIBZ lib lib 0 "/usr/lib/libz.so:/usr/lib/libz.a:/usr/lib/$hwpl-linux-$gnu/libz.so" pwre_config_check_lib libz LIBZ lib lib 0 "/usr/lib/libz.so:/usr/lib/libz.a:/usr/lib/$hwpl-linux-$gnu/libz.so"
pwre_config_check_lib libcrypt LIBCRYPT lib lib 0 "/usr/lib/libcrypt.so:/usr/lib/libcrypt.a:/usr/lib/$hwpl-linux-$gnu/libcrypt.so" pwre_config_check_lib libcrypt LIBCRYPT lib lib 0 "/usr/lib/libcrypt.so:/usr/lib/libcrypt.a:/usr/lib/$hwpl-linux-$gnu/libcrypt.so"
pwre_config_check_lib librt LIBRT lib lib 0 "/usr/lib/librt.so:/usr/lib/librt.a:/usr/lib/$hwpl-linux-$gnu/librt.so" pwre_config_check_lib librt LIBRT lib lib 0 "/usr/lib/librt.so:/usr/lib/librt.a:/usr/lib/$hwpl-linux-$gnu/librt.so"
pwre_config_check_lib libfl LIBFL lib lib 0 "/usr/lib/libfl.so:/usr/lib/libfl.a:/usr/lib/$hwpl-linux-$gnu/libfl.so"
pwre_config_check_lib libX11 LIBX11 lib lib 0 "/usr/lib/libX11.so:/usr/lib/$hwpl-linux-$gnu/libX11.so" pwre_config_check_lib libX11 LIBX11 lib lib 0 "/usr/lib/libX11.so:/usr/lib/$hwpl-linux-$gnu/libX11.so"
pwre_config_check_include alsa ALSA 1 "/usr/include/alsa/asoundlib.h" pwre_config_check_include alsa ALSA 1 "/usr/include/alsa/asoundlib.h"
......
...@@ -247,12 +247,9 @@ KRB5_LIBS = ...@@ -247,12 +247,9 @@ KRB5_LIBS =
LAUNCHSERVICES_FRAMEWORKS = LAUNCHSERVICES_FRAMEWORKS =
LD = /usr/bin/ld LD = /usr/bin/ld
LDFLAGS = -Wl,--as-needed -L/usr/local/lib -L/usr/local/lib -L/usr/local/lib -L/usr/local/lib -L/usr/local/lib LDFLAGS = -Wl,--as-needed -L/usr/local/lib -L/usr/local/lib -L/usr/local/lib -L/usr/local/lib -L/usr/local/lib
LDFLAGS_SHAREDLIB = LDFLAGS_SHAREDLIB =
LEX = /usr/bin/flex LIBCAP_LIBS =
LEXLIB = -lfl LIBGCRYPT_CFLAGS =
LEX_OUTPUT_ROOT = lex.yy
LIBCAP_LIBS =
LIBGCRYPT_CFLAGS =
LIBGCRYPT_CONFIG = no LIBGCRYPT_CONFIG = no
LIBGCRYPT_LIBS = LIBGCRYPT_LIBS =
LIBGNUTLS_CFLAGS = LIBGNUTLS_CFLAGS =
......
...@@ -248,9 +248,6 @@ LAUNCHSERVICES_FRAMEWORKS = @LAUNCHSERVICES_FRAMEWORKS@ ...@@ -248,9 +248,6 @@ LAUNCHSERVICES_FRAMEWORKS = @LAUNCHSERVICES_FRAMEWORKS@
LD = @LD@ LD = @LD@
LDFLAGS = @LDFLAGS@ LDFLAGS = @LDFLAGS@
LDFLAGS_SHAREDLIB = @LDFLAGS_SHAREDLIB@ LDFLAGS_SHAREDLIB = @LDFLAGS_SHAREDLIB@
LEX = @LEX@
LEXLIB = @LEXLIB@
LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@
LIBCAP_LIBS = @LIBCAP_LIBS@ LIBCAP_LIBS = @LIBCAP_LIBS@
LIBGCRYPT_CFLAGS = @LIBGCRYPT_CFLAGS@ LIBGCRYPT_CFLAGS = @LIBGCRYPT_CFLAGS@
LIBGCRYPT_CONFIG = @LIBGCRYPT_CONFIG@ LIBGCRYPT_CONFIG = @LIBGCRYPT_CONFIG@
......
...@@ -248,9 +248,6 @@ LAUNCHSERVICES_FRAMEWORKS = ...@@ -248,9 +248,6 @@ LAUNCHSERVICES_FRAMEWORKS =
LD = /usr/bin/ld LD = /usr/bin/ld
LDFLAGS = -Wl,--as-needed -L/usr/lib -L/usr/local/lib -L/usr/local/lib -L/usr/local/lib -L/usr/local/lib LDFLAGS = -Wl,--as-needed -L/usr/lib -L/usr/local/lib -L/usr/local/lib -L/usr/local/lib -L/usr/local/lib
LDFLAGS_SHAREDLIB = LDFLAGS_SHAREDLIB =
LEX = /usr/bin/flex
LEXLIB = -lfl
LEX_OUTPUT_ROOT = lex.yy
LIBCAP_LIBS = -lcap LIBCAP_LIBS = -lcap
LIBGCRYPT_CFLAGS = LIBGCRYPT_CFLAGS =
LIBGCRYPT_CONFIG = /usr/bin/libgcrypt-config LIBGCRYPT_CONFIG = /usr/bin/libgcrypt-config
......
...@@ -248,9 +248,6 @@ LAUNCHSERVICES_FRAMEWORKS = @LAUNCHSERVICES_FRAMEWORKS@ ...@@ -248,9 +248,6 @@ LAUNCHSERVICES_FRAMEWORKS = @LAUNCHSERVICES_FRAMEWORKS@
LD = @LD@ LD = @LD@
LDFLAGS = @LDFLAGS@ LDFLAGS = @LDFLAGS@
LDFLAGS_SHAREDLIB = @LDFLAGS_SHAREDLIB@ LDFLAGS_SHAREDLIB = @LDFLAGS_SHAREDLIB@
LEX = @LEX@
LEXLIB = @LEXLIB@
LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@
LIBCAP_LIBS = @LIBCAP_LIBS@ LIBCAP_LIBS = @LIBCAP_LIBS@
LIBGCRYPT_CFLAGS = @LIBGCRYPT_CFLAGS@ LIBGCRYPT_CFLAGS = @LIBGCRYPT_CFLAGS@
LIBGCRYPT_CONFIG = @LIBGCRYPT_CONFIG@ LIBGCRYPT_CONFIG = @LIBGCRYPT_CONFIG@
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment