"Fossies" - the Fresh Open Source Software Archive

Member "asp2php-2008-08-13/src/jscript/function_j.c" (13 Aug 2008, 6766 Bytes) of package /linux/www/old/asp2php-2008-08-13.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "function_j.c" see the Fossies "Dox" file reference documentation.

    1 #include <stdio.h>
    2 #include <stdlib.h>
    3 #include <string.h>
    4 #include <ctype.h>
    5 
    6 #include "../globals.h"
    7 #include "../functions.h"
    8 
    9 
   10 /* checks to see if the current token is a known
   11    defined function */
   12 
   13 /*
   14 int isfunction_j(char *token)
   15 {
   16 int t=0;
   17 
   18   for (t=0; t<functptr; t++)
   19   { if (strcasecmp(funct[t],token)==0) return 1; }
   20 
   21   return 0;
   22 }
   23 */
   24 
   25 /*
   26 int parse_funct_j(int isfunct)
   27 {
   28 char token[TOKENSIZE];
   29 char newtoken[LINELENGTH];
   30 int tokentype,c;
   31 
   32   infunct=isfunct; 
   33 
   34   tokentype=gettoken_j(token);
   35   fprintf(out,"function %s",token);
   36 
   37   tokentype=gettoken_j(token);
   38   push(token,tokentype);
   39 
   40   newtoken[0]=0;
   41 
   42   if (strcmp(token,"(")==0)
   43   { eval_funct(newtoken); fprintf(out,"(%s)",newtoken); }
   44     else
   45   { fprintf(out,"()"); }
   46 
   47   fprintf(out,"\n");
   48   autoindent();
   49 
   50   fprintf(out,"{\n");
   51   autoindent();
   52   fprintf(out,"  global extract($GLOBALS);\n\n");
   53 
   54   indent++;
   55   c=parse_body(0);
   56 
   57   autoindent();
   58   fprintf(out,"return $function_ret;\n");
   59   indent--;
   60   autoindent();
   61   fprintf(out,"} ");
   62 
   63   tokentype=gettoken_j(token);
   64 
   65   if (isfunct==1)
   66   {
   67     if (strcasecmp(token,"function")!=0)
   68     { error(token,"function","parse_funct"); }
   69   }
   70     else
   71   if (isfunct==2)
   72   {
   73     if (strcasecmp(token,"sub")!=0)
   74     { error(token,"sub","parse_funct"); }
   75   }
   76   infunct=0;
   77 
   78   return 0;
   79 }
   80 */
   81 
   82 /*
   83 int eval_funct_j(char *newtoken)
   84 {
   85 int tokentype;
   86 char token[TOKENSIZE];
   87 int parencount=1;
   88 char molecule[LINELENGTH];
   89 
   90   tokentype=gettoken_j(token);
   91   if (strcmp("(",token)!=0)
   92   { 
   93     push(token,tokentype);
   94     strcat(newtoken,"()");
   95     return 0; 
   96   }
   97 
   98   while((tokentype=gettoken_j(token))!=0)
   99   {
  100     if (strcmp("(",token)==0)
  101     { parencount++; strcat(newtoken,"("); }
  102       else
  103     if (strcmp(")",token)==0)
  104     {
  105       parencount--;
  106       if (parencount!=0)
  107       { strcat(newtoken,")"); }
  108         else
  109       { break; }
  110     }
  111       else
  112     if (strcmp(",",token)==0)
  113     { strcat(newtoken,","); }
  114       else
  115     {
  116       eval_token_j(molecule,tokentype,token);
  117       strcat(newtoken,molecule);
  118     }
  119   }
  120 
  121   return 0;
  122 }
  123 */
  124 
  125 /*
  126 
  127 supress flags:
  128 
  129 bit 0: supress parenthesis
  130 bit 1: supress , between params. use . instead
  131 bit 2: don't put more PHP params than there are asp params
  132 bit 3: Fix windows paths in strings 
  133 bit 4: This is an array, not a function
  134 
  135 */
  136 
  137 void convert_funct_j(char *newtoken, char *params1, int suppress)
  138 {
  139 char params[256];
  140 char molecule[LINELENGTH];
  141 char temp[LINELENGTH];
  142 int paramptr[50];
  143 int param_count;
  144 int parens,pflag,tokentype,isstring,t,m,l,k,n;
  145 char token[TOKENSIZE];
  146 char s[10];
  147 char extra[256];
  148 
  149 #ifdef DEBUG
  150 printf("\nENTERING convert_funct_j()\n");
  151 #endif
  152 
  153   strcpy(params,params1);
  154   parens=0;
  155   molecule[0]=0;
  156   pflag=0;
  157   isstring=0;
  158 
  159   param_count=0;
  160   paramptr[0]=0;
  161 
  162   tokentype=gettoken_j(token);
  163 
  164   if (strcmp(token,"(")==0)
  165   {
  166     parens++;
  167     pflag=1;
  168   }
  169     else
  170   { push(token,tokentype); }
  171 
  172   while(1)
  173   {
  174 #ifdef DEBUG
  175 printf("token: %s (%d)\n",token,tokentype);
  176 #endif
  177     tokentype=gettoken_j(token);
  178     /* if (tokentype==5) break; */
  179     if (tokentype==0) return;
  180     if (tokentype==10 || tokentype==11) isstring=1;
  181     if (tokentype==15 || tokentype==5 || tokentype==6 || tokentype==17)
  182     {
  183       push(token,tokentype);
  184       break;
  185     }
  186 
  187     if (spacer==1) strcat(&molecule[paramptr[param_count]]," ");
  188 
  189     if (strcmp(token,"(")==0)
  190     {
  191       parens++;
  192       strcat(&molecule[paramptr[param_count]],"(");
  193     }
  194       else
  195     if (strcmp(token,")")==0)
  196     {
  197       parens--;
  198       if (parens==0 && pflag==1) break;
  199       if (parens<0)
  200       {
  201         push(token,tokentype);
  202         break;
  203       }
  204       strcat(&molecule[paramptr[param_count]],")");
  205     }
  206       else
  207     if (strcmp(token,"+")==0 && isstring==1)
  208     { strcat(&molecule[paramptr[param_count]],"."); }
  209       else
  210     if (tokentype==7 || tokentype==1 || tokentype==8 || tokentype==9 ||
  211         tokentype==3 || tokentype==18)
  212     { 
  213       strcat(&molecule[paramptr[param_count]],token);
  214 #ifdef DEBUG
  215 printf("molecule: %s token: %s\n",&molecule[paramptr[param_count]],token);
  216 #endif
  217     }
  218       else
  219     if (tokentype==16)
  220     {
  221       t=find_null(molecule,paramptr[param_count]);
  222 #ifdef DEBUG
  223 printf("Found null: %d\n",t);
  224 #endif
  225       param_count++;
  226       paramptr[param_count]=t+1;
  227       molecule[t+1]=0;
  228     }
  229       else
  230     if (tokentype==10 || tokentype==11)
  231     {
  232       if ((suppress&8)!=0)
  233       { if (fixwin95paths==1) fixwinpath(token); }
  234       strcat(&molecule[paramptr[param_count]],token);
  235     }
  236       else
  237     {
  238       eval_token_j(temp,tokentype,token);
  239       strcat(&molecule[paramptr[param_count]],temp);
  240     }
  241   }
  242 
  243   if (parens!=0)
  244   { printf("Warning: Unbalanced parenthesis on line %d\n",line); } 
  245 
  246 #ifdef DEBUG
  247   for (l=0; l<=param_count; l++)
  248   {
  249     printf(">> %d: (%d),%s\n",l,paramptr[l],&molecule[paramptr[l]]);
  250   }
  251 #endif
  252 
  253   strcat(params,"\n");
  254   t=strlen(params);
  255   s[0]=0;
  256   pflag=0;
  257   m=0;
  258 
  259   if ((suppress&16)==16)
  260   { strcat(newtoken,"["); }
  261     else
  262   if ((suppress&1)==0)
  263   { strcat(newtoken,"("); }
  264 
  265   extra[0]=0;
  266 
  267   for(l=0; l<t; l++)
  268   {
  269     if ((suppress&4)!=0 && pflag>param_count)
  270     { break; }
  271 
  272     if (params[l]=='-' || params[l]=='+' || params[l]=='@')
  273     {
  274       k=0;
  275       while(params[l]!=',' && params[l]!='\n')
  276       { extra[k++]=params[l++]; }
  277 
  278       extra[k]=0;
  279 #ifdef DEBUG
  280 printf("atoi extra=%d\n",atoi(extra));
  281 #endif
  282 
  283       if (extra[0]=='@')
  284       {
  285         if (pflag!=0)
  286         {
  287           if ((suppress&2)==0)
  288           { strcat(newtoken,","); }
  289             else
  290           { strcat(newtoken,"."); }
  291         }
  292         strcat(newtoken,&extra[1]);
  293 
  294         s[0]=0;
  295         extra[0]=0;
  296         pflag++;
  297         m=0;
  298 
  299         if (params[l]=='\n') break;
  300         continue;
  301       }
  302     }
  303 
  304     if (params[l]==',' || params[l]=='\n')
  305     {
  306       s[m]=0;
  307       m=atoi(s);
  308       if (m!=0)
  309       {
  310         if (pflag!=0)
  311         {
  312           if ((suppress&16)==16)
  313           { strcat(newtoken,"]["); }
  314             else
  315           if ((suppress&2)==0)
  316           { strcat(newtoken,","); }
  317             else
  318           { strcat(newtoken,"."); }
  319         }
  320 
  321         m--;
  322         if (m<=param_count)
  323         {
  324           if (isnum(&molecule[paramptr[m]])==1 && atoi(extra)!=0)
  325           {
  326             n=atoi(&molecule[paramptr[m]])+atoi(extra);
  327             sprintf(extra,"%d",n);
  328 #ifdef DEBUG
  329 printf("extra to append: %s\n",extra);
  330 #endif
  331             strcat(newtoken,extra);
  332           }
  333             else
  334           {
  335             strcat(newtoken,&molecule[paramptr[m]]);
  336             strcat(newtoken,extra);
  337           }
  338         }
  339 
  340         s[0]=0;
  341         extra[0]=0;
  342         pflag++;
  343         m=0;
  344       }
  345       if (params[l]=='\n') break;
  346     }
  347       else
  348     { s[m++]=params[l]; }
  349   }
  350 
  351   if ((suppress&16)==16)
  352   { strcat(newtoken,"]"); }
  353     else
  354   if ((suppress&1)==0)
  355   { strcat(newtoken,")"); }
  356 }
  357 
  358