Initial revision
[charm.git] / src / xlat / xl-sfspec.flex
1 %{
2 #include <string.h>
3 int currentline=1;
4
5 #ifdef yywrap
6 #undef yywrap
7 #endif
8 %}
9
10 WS [ \t\n]*
11 WSN [ \t]*
12
13 %%
14 CreateChare{WS}"("      { CheckReturns(yytext);fprintf(yyout,"CreateChare("); }
15 CreateBoc{WS}"("        { CheckReturns(yytext);fprintf(yyout,"CreateBoc("); }
16 MyBocNum{WS}"("         { CheckReturns(yytext);fprintf(yyout,"MyBocNum("); }
17 MyBranchID{WS}"("       { CheckReturns(yytext);fprintf(yyout,"MyBranchID("); }
18 SendMsgBranch{WS}"("    { CheckReturns(yytext);fprintf(yyout,"SendMsgBranch("); }
19 ImmSendMsgBranch{WS}"(" { CheckReturns(yytext);fprintf(yyout,"ImmSendMsgBranch("); }
20 BroadcastMsgBranch{WS}"("  { CheckReturns(yytext);fprintf(yyout,"BroadcastMsgBranch("); }
21 "#"{WSN}[line]?{WSN}[0-9]+ { currentline=GetLine(yytext);fprintf(yyout,"%s",yytext); }
22 "#"{WSN}[line]?{WSN}[0-9]+{WSN}\"[^\n]*\"{WSN}[0-9]+ { currentline = GetLine(yytext);
23                            output_proper_line(yytext);}
24 .                       { CountReturns(yytext); fprintf(yyout,"%s",yytext); }
25 %%
26
27 yywrap(){ return(1); }
28
29 main() { writem4(); writeundef(); yylex(); }
30
31 GetLine(string)
32 char string[];
33 { int i=0,j;
34   char dummy[10];
35
36   while ((string[i]<'0')||(string[i]>'9')) i++;
37   j=0;
38   while ((string[i]>='0')&&(string[i]<='9')) dummy[j++] = string[i++];
39   dummy[j]='\0';
40   return(atoi(dummy));
41 }
42
43 output_proper_line(string)
44 char string[];
45 {
46    int length;
47
48    length=strlen(string)-1;
49    while (string[length-1]!='"') length--;
50    string[length]='\0';
51    fprintf(yyout,"%s",string);
52 }
53
54 CountReturns(string)
55 char *string;
56 {
57   while (*string) {
58     if (*string=='\n') currentline++;
59     string++;
60   }
61 }
62
63 CheckReturns(string)
64 char *string;
65 {
66   int anyret=0;
67   while (*string) {
68     if (*string=='\n') { currentline++; anyret=1; }
69     string++;
70   }
71   if (anyret)
72     fprintf(yyout,"# line %d\n",currentline);
73 }
74
75
76 char *createchare="define(CreateChare,`_CK_CreateChare($1,$2,$3,ifelse($4,,NULL_VID,$4),ifelse($5,,NULL_PE,$5))')";
77
78 char *createboc="define(CreateBoc,`_CK_CreateBoc($1,$2,$3,ifelse($4,,-1`,'NULL,$4`,'$5))')";
79
80 char *mybocnum="define(MyBocNum,`_CK_MyBocNum(_CK_4mydata)')";
81 char *mybranchid="define(MyBranchID,`_CK_MyBranchID($1,_CK_4mydata)')";
82 char *sendmsgbranch="define(SendMsgBranch,`_CK_SendMsgBranch($1,$2,ifelse($4,,_CK_MyBocNum(_CK_4mydata),$4),$3)')";
83 char *immsendmsgbranch="define(ImmSendMsgBranch,`_CK_ImmSendMsgBranch($1,$2,ifelse($4,,_CK_MyBocNum(_CK_4mydata),$4),$3)')";
84 char *broadcastmsgbranch="define(BroadcastMsgBranch,`_CK_BroadcastMsgBranch($1,$2,ifelse($3,,_CK_MyBocNum(_CK_4mydata),$3))')";
85 char *createacc="define(CreateAcc,`_CK_CreateAcc($1,$2,ifelse($3,,-1`,'NULL,$3`,'$4))')";
86 char *createmono="define(CreateMono,`_CK_CreateMono($1,$2,ifelse($3,,-1`,'NULL,$3`,'$4))')";
87
88 writem4()
89 { printf("%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",createchare,createboc,mybocnum,mybranchid,
90                 sendmsgbranch,immsendmsgbranch,broadcastmsgbranch,createacc,createmono);
91 }
92
93 writeundef()
94 { printf("undefine(`changequote')\n");
95   printf("undefine(`divert')\n");
96   printf("undefine(`divnum')\n");
97   printf("undefine(`dnl')\n");
98   printf("undefine(`dumpdef')\n");
99   printf("undefine(`errprint')\n");
100   printf("undefine(`eval')\n");
101   printf("undefine(`ifdef')\n");
102   printf("undefine(`include')\n");
103   printf("undefine(`incr')\n");
104   printf("undefine(`index')\n");
105   printf("undefine(`len')\n");
106   printf("undefine(`maketemp')\n");
107   printf("undefine(`sinclude')\n");
108   printf("undefine(`substr')\n");
109   printf("undefine(`syscmd')\n");
110   printf("undefine(`translit')\n");
111   printf("undefine(`undivert')\n");
112   printf("undefine(`define')\n");
113   printf("undefine(`undefine')\n");
114 }