Пример #1
0
/*
 * Print the sub-tree of ScriptArg *a
 */
void printcode(ScriptArg *a, int x)
{
int i;
    /* Don't produce a SegFault if pointer is non-NULL */
    if ((long int)a > 1000)
    {
	for ( i = 0 ; i < x ; i++ )
	    printf(" ");
	printf("%ld: %s , cmd=%ld, next=%ld, parent=%ld\n",(long int)a,a->arg,(long int)a->cmd,(long int)a->next,(long int)a->parent);
	printcode(a->cmd, x+1);
	printcode(a->next, x);
    }
}
Пример #2
0
/* dump out a Paragraph in the desired manner
 */
static Paragraph*
display(Paragraph *p, MMIOT *f)
{
    if ( !p ) return 0;
    
    switch ( p->typ ) {
    case STYLE:
    case WHITESPACE:
	break;

    case HTML:
	printhtml(p->text, f);
	break;
	
    case CODE:
	printcode(p->text, f);
	break;
	
    case QUOTE:
	htmlify(p->down, p->ident ? "div" : "blockquote", p->ident, f);
	break;
	
    case UL:
    case OL:
    case AL:
	listdisplay(p->typ, p->down, f);
	break;

#if DL_TAG_EXTENSION
    case DL:
	definitionlist(p->down, f);
	break;
#endif

    case HR:
	Qstring("<hr />", f);
	break;

    case HDR:
	printheader(p, f);
	break;

    case TABLE:
	printtable(p, f);
	break;

    case SOURCE:
	htmlify(p->down, 0, 0, f);
	break;
	
    default:
	printblock(p, f);
	break;
    }
    return p->next;
}
Пример #3
0
int simreceive(struct ir_remote* remotes)
{
	char* code = NULL;
	int at_eof;

	do {
		code = curr_driver->rec_func(remotes);
		at_eof = code != NULL && strstr(code, "__EOF") != NULL;
		if (code != NULL && !at_eof) {
			printcode(code);
			fflush(stdout);
		}
	} while (!at_eof);
	return 0;
}
Пример #4
0
/*
 * Read in file and generate executable tree
 */
void parse_file(ScriptArg *first)
{
ScriptArg *current;
int count, i, j, ready;
char **mclip;

    ready = FALSE;
    current = first;
    do
    {
	count = Read(inputfile, &buffer[0], 1);
	if (count == 0)
	{
	    PrintFault(IoErr(), INSTALLER_NAME);
	    show_parseerror("End of File", line);
	    cleanup();
	    exit(-1);
	}
	if (!isspace(buffer[0]))
	{
	    switch (buffer[0])
	    {
		case SEMICOLON: /* A comment, ok - Go on with next line */
		    do
		    {
			count = Read(inputfile, &buffer[0], 1);
		    } while (buffer[0] != LINEFEED && count != 0);
		    line++;
		    break;

		case LBRACK: /* Open bracket: recurse into next level */
		    current->cmd = AllocVec(sizeof(ScriptArg), MEMF_PUBLIC);
		    if (current->cmd == NULL)
		    {
			end_alloc();
		    }
		    /* Set initial values */
		    current->cmd->parent = current;
		    current->cmd->arg = NULL;
		    current->cmd->cmd = NULL;
		    current->cmd->next = NULL;
		    current->cmd->intval = 0;
		    current->cmd->ignore = 0;
		    parse_file(current->cmd);
		    current->next = AllocVec(sizeof(ScriptArg), MEMF_PUBLIC);
		    if (current->next == NULL)
		    {
			end_alloc();
		    }
		    current->next->parent = current->parent;
		    /* Set initial values */
		    current = current->next;
		    current->arg = NULL;
		    current->cmd = NULL;
		    current->next = NULL;
		    current->intval = 0;
		    current->ignore = 0;
		    break;

		case RBRACK: /* All args collected return to lower level */
		    /* We have allocated one ScriptArg too much */
		    current = current->parent->cmd;
		    if (current->next != NULL)
		    {
			while (current->next->next != NULL)
			{
			    current = current->next;
			}
			FreeVec(current->next);
			current->next = NULL;
		    }
		    else
		    {
			/* This is an empty bracket */
			show_parseerror("There is an empty bracket.", line);
			cleanup();
			exit(-1);
		    }
		    ready = TRUE;
		    break;

		default: /* This is the real string */
		    i = 0;
		    if (buffer[0] == DQUOTE || buffer[0] == SQUOTE)
		    {
		    int masquerade = FALSE;
			do
			{
			    if (masquerade == TRUE)
			    {
				switch (buffer[i])
				{
				    case 'n': /* NEWLINE */
					buffer[i-1] = 0x0a;
						  break;
				    case 'r': /* RETURN */
					buffer[i-1] = 0x0d;
					break;
				    case 't': /* TAB */
					buffer[i-1] = 0x09;
					break;
				    case SQUOTE: /* SQUOTE */
					buffer[i-1] = SQUOTE;
					break;
				    case DQUOTE: /* DQUOTE */
					 buffer[i-1] = DQUOTE;
					 break;
				    case BACKSLASH: /* BACKSLASH */
					 buffer[i-1] = BACKSLASH;
					 break;
#warning TODO: convert missing '\\' masqueraded symbols
				    case 'h': /* H.TAB */
				    case 'v': /* V.TAB */
				    case 'b': /* BACKSPACE */
				    case 'f': /* FORMFEED */
				    case 'x': /* HEX number */
				    case 'o': /* \\ooo OCTAL number ('o' is just to remember) */
				    default:
					i++;
					break;
				}
				masquerade = FALSE;
			    }
			    else
			    {
				if (buffer[i] == BACKSLASH)
				    masquerade = TRUE;
				i++;
			    }
			    if (i == MAXARGSIZE)
			    {
				show_parseerror("Argument length overflow!" ,line);
				cleanup();
				exit(-1);
			    }
			    count = Read(inputfile, &buffer[i], 1);
			} while (masquerade || (buffer[i] != buffer[0] && count != 0));
			current->arg = AllocVec(sizeof(char)*(i+2), MEMF_PUBLIC);
			if (current->arg == NULL)
			{
			    end_alloc();
			}
			buffer[i+1] = 0;
			strncpy (current->arg, buffer, i+2);
		    }
		    else
		    {
			do
			{
			    i++;
			    count = Read(inputfile, &buffer[i], 1);
			} while (!isspace(buffer[i]) && buffer[i]!=LBRACK && buffer[i]!=RBRACK && buffer[i]!=SEMICOLON && count != 0 && i < MAXARGSIZE);
			if (buffer[i] == LINEFEED)
			{
			    line++;
			}
			if (i == MAXARGSIZE)
			{
			    show_parseerror("Argument length overflow!", line);
			    cleanup();
			    exit(-1);
			}
			if (buffer[i] == SEMICOLON)
			{
			    do
			    {
				count = Read(inputfile, &buffer[i], 1);
			    } while (buffer[i] != LINEFEED && count != 0);
			    line++;
			}
			if (buffer[i] == LBRACK || buffer[i] == RBRACK)
			{
			    Seek(inputfile, -1 , OFFSET_CURRENT);
			}
			buffer[i] = 0;
			switch (buffer[0])
			{
			    case DOLLAR: /* HEX number */
				current->intval = strtol(&buffer[1], NULL, 16);
					    break;
			    case PERCENT: /* binary number */
				current->intval = strtol(&buffer[1], NULL, 2);
				break;
			    default: /* number or variable */
				if (isdigit(buffer[0]) || ((buffer[0] == PLUS || buffer[0] == MINUS) && isdigit(buffer[1])))
				{
				    current->intval = atol(buffer);
				}
				else
				{
				    current->arg = AllocVec(sizeof(char)*(i+1), MEMF_PUBLIC);
				    if (current->arg == NULL)
				    {
					end_alloc();
				    }
				    strncpy(current->arg, buffer, i+1);
				}
				if (current == current->parent->cmd && strcasecmp(buffer, "procedure") == 0)
				{
				ScriptArg *proc, *uproc;
				int finish;
				    /* Save procedure in ProcedureList */
				    proc = AllocVec(sizeof(ScriptArg), MEMF_PUBLIC);
				    if (proc == NULL)
				    {
					end_alloc();
				    }
				    uproc = proc;
				    proc->parent = NULL;
				    proc->next = NULL;
				    proc->arg = NULL;
				    proc->intval = 0;
				    proc->ignore = 0;
				    proc->cmd = AllocVec(sizeof(ScriptArg), MEMF_PUBLIC);
				    if (proc->cmd == NULL)
				    {
					end_alloc();
				    }
				    proc->cmd->parent = proc;
				    proc->cmd->next = NULL;
				    proc->cmd->arg = NULL;
				    proc->cmd->intval = 0;
				    proc->cmd->ignore = 0;
				    proc = proc->cmd;
				    proc->cmd = AllocVec(sizeof(ScriptArg), MEMF_PUBLIC);
				    if (proc->cmd == NULL)
				    {
					end_alloc();
				    }
				    proc->cmd->parent = proc;
				    proc->cmd->next = NULL;
				    proc->cmd->arg = NULL;
				    proc->cmd->intval = 0;
				    proc->cmd->ignore = 0;
				    proc->cmd->cmd = NULL;
				    /* parse procedure name and args */
				    mclip = NULL;
				    j = 0;
				    finish = FALSE;
				    do
				    {
					/* goto next argument */
					do
					{
					    count = Read(inputfile, &buffer[0], 1);
					    if (buffer[0] == LINEFEED)
					    {
						line++;
					    }
					    if (buffer[0] == RBRACK)
					    {
						if (j > 0)
						{
						    show_parseerror("Procedure has no body!", line);
						}
						else
						{
						    show_parseerror("Procedure has no name!", line);
						}
						cleanup();
						exit(-1);
					    }
					    if (buffer[0] == SQUOTE ||  buffer[0] == DQUOTE)
					    {
						show_parseerror("Procedure has a quoted argument!", line);
						cleanup();
						exit(-1);
					    }
					    if (buffer[0] == SEMICOLON && count != 0)
					    {
						do
						{
						    count = Read(inputfile, &buffer[0], 1);
						} while (buffer[0] != LINEFEED && count != 0);
						line++;
					    }
					} while (isspace(buffer[0]) && count != 0);

					if (buffer[0] != LBRACK)
					{
					    i = 0;
					    /* read in string */
					    do
					    {
						i++;
						count = Read(inputfile, &buffer[i], 1);
					    } while (!isspace(buffer[i]) && buffer[i]!=LBRACK && buffer[i]!=RBRACK && buffer[i]!=SEMICOLON && count != 0 && i < MAXARGSIZE);
					    if (i == MAXARGSIZE)
					    {
						show_parseerror("Argument length overflow!", line);
						cleanup();
						exit(-1);
					    }
					    if (buffer[i] == LINEFEED)
					    {
						line++;
					    }
					    if (buffer[i] == LBRACK || buffer[i] == RBRACK || buffer[i] == SEMICOLON)
					    {
						Seek(inputfile, -1 , OFFSET_CURRENT);
					    }
					    buffer[i] = 0;
					    j++;
					    mclip = ReAllocVec(mclip, sizeof(char *) * j, MEMF_PUBLIC);
					    if (mclip == NULL)
					    {
						end_alloc();
					    }
					    mclip[j-1] = StrDup(buffer);
					    if (mclip[j-1] == NULL)
					    {
						end_alloc();
					    }
					}
					else
					{
					    /* Exit if procedure has no name or name is string/digit or bracket follows */
					    if (j == 0)
					    {
						show_parseerror("Argument to procedure is a command!\n", line);
						cleanup();
						exit(-1);
					    }
					    /* Next string is body-command */
					    finish = TRUE;
					}
				    } while (!finish);
				    /* Procedure body */
				    parse_file(proc->cmd);
				    finish = FALSE;
				    do
				    {
					do
					{
					    count = Read(inputfile, &buffer[0], 1);
					    if (buffer[0] == LINEFEED)
					    {
						line++;
					    }
					} while (isspace(buffer[0]) && count != 0);
					if (buffer[0] == SEMICOLON)
					{
					    do
					    {
						count = Read(inputfile, &buffer[0], 1);
					    } while (buffer[0] != LINEFEED && count != 0);
					    line++;
					}
					else if (buffer[0] == LBRACK)
					{
					    proc->next = AllocVec(sizeof(ScriptArg), MEMF_PUBLIC);
					    if (proc->next == NULL)
					    {
						end_alloc();
					    }
					    proc->next->parent = proc->parent;
					    proc->next->next = NULL;
					    proc->next->arg = NULL;
					    proc->next->intval = 0;
					    proc->next->ignore = 0;
					    proc = proc->next;
					    proc->cmd = AllocVec(sizeof(ScriptArg), MEMF_PUBLIC);
					    if (proc->cmd == NULL)
					    {
						end_alloc();
					    }
					    proc->cmd->parent = proc;
					    proc->cmd->next = NULL;
					    proc->cmd->arg = NULL;
					    proc->cmd->intval = 0;
					    proc->cmd->ignore = 0;
					    proc->cmd->cmd = NULL;
					    parse_file(proc->cmd);
					}
					else if (buffer[0] == RBRACK)
					{
					    finish = TRUE;
					}
					else
					{
					    show_parseerror("Procedure has rubbish in its body!", line);
					    cleanup();
					    exit(-1);
					}
				    } while (!finish);
				    current->next = AllocVec(sizeof(ScriptArg), MEMF_PUBLIC);
				    if (current->next == NULL)
				    {
					end_alloc();
				    }
				    current->next->parent = current->parent;
				    current = current->next;
				    current->arg = mclip[0];
				    current->cmd = NULL;
				    current->next = NULL;
				    current->intval = set_procedure(mclip, j, uproc);
				    current->ignore = 0;
#ifdef DEBUG
	printf("\n\n");
	printcode(uproc, 0);
#endif /* DEBUG */
				    buffer[0] = 0;
				    ready = TRUE;
				}
				if (current->arg == current->parent->cmd->arg && strcasecmp(buffer, "welcome") == 0)
				{
				    preferences.welcome = TRUE;
				}
				break;
			}
		    }
		    current->next = AllocVec(sizeof(ScriptArg), MEMF_PUBLIC);
		    if (current->next == NULL)
		    {
			end_alloc();
		    }
		    current->next->parent = current->parent;
		    current = current->next;
		    /* Set initial values */
		    current->arg = NULL;
		    current->cmd = NULL;
		    current->next = NULL;
		    current->intval = 0;
		    current->ignore = 0;
		    break;
	    }
	}
	else
	{
	    if (buffer[0] == LINEFEED)
	    {
		line++;
	    }
	}
	if (count == 0)
	{
	    PrintFault(IoErr(), INSTALLER_NAME);
	    show_parseerror("End of File", line);
	    cleanup();
	    exit(-1);
	}
    } while (!ready);
}
Пример #5
0
main()
{
    int fl,o,i=1,j=0,tn,re,scr=1,k=1,l=0,m=0;
    char ex0,ch,ch2,are[9],cds[16];
    FILE *fp,*ft;
    clrscr();
    fp=fopen("zahid.zad","r");
    fl=ftell(fp);
    fseek(fp,-1,SEEK_END);
    ex0=fgetc(fp);
    printf("%c",ex0);
    fseek(fp,fl,SEEK_SET);

    fscanf(fp,"%d",&n);
    printf("%d\n",n);
    tn=2*n-1;
    for(i=1; i<=n; i++)
    {
        ch=fgetc(fp);
        fscanf(fp,"%d",&a);
        tree[i+n][0]=a;
        ch=fgetc(fp);
        alpha[i]=ch;
        fscanf(fp,"%d",&a);
        tree[i+n][1]=a;
    }
    Rec(tn,0);
    printcode();

    while(ch!=' ')
    {
        ch=fgetc(fp);
        numvl=ch;
    }

    o=7;
    i=0;
    while(ch!=EOF)
    {
        o=7;
        if(c==0)
            ch=fgetc(fp);
        else {
            ch=ch2;
            c=0;
        }
        delay(10);
        numvl=ch;
        if(ch=='1'||ch=='2')
        {   if(ch=='1') {
                {   ch2=fgetc(fp);
                    if(ch2=='3')  numvl=13;
                    else c=1;
                }
            }

            if(ch=='2')
            {   ch2=fgetc(fp);
                if(ch2=='6')  numvl=26;
                else if(ch2=='5')  {
                    numvl=255;
                    fgetc(fp);
                }
                else c=1;
            }
        }
        if(numvl<0) numvl=256+numvl;
        while(numvl!=1)
        {
            re=numvl%2;
            numvl/=2;
            if(re==1) are[o--]='1';
            else are[o--]='0';
        }
        are[o--]='1';
        while(o!=-1)
            are[o--]='0';

        are[8]='\x0';
        j=0;
        while(are[j])
        {
            cds[i++]=are[j++];
        }
        cds[i++]='\x0';
        i=0;
        l=0;

        while(cds[l]!='\x0')
        {
            k=1;
            are[i++]=cds[l];
            are[i]='\x0';
            l++;
            while(k!=n+1)
            {
                scr=strcmp(are,codes[k]);
                k++;
                if(scr==0)
                {   m=l;
                    k--;
                    printf("%c",alpha[k]);
                    i=0;
                    break;
                }
            }
        }
        i=0;
        while(cds[m]!='\x0')
        {
            cds[i++]=cds[m++];
        }
        cds[i]='\x0';
    }
    getch();
}
Пример #6
0
/* dump out a Paragraph in the desired manner
 */
static Paragraph*
display(Paragraph *p, MMIOT *f, int easyNewLine)
{
    if ( !p ) return 0;

    switch ( p->typ ) {
    case STYLE:
    case WHITESPACE:
	break;

    case HTML:
	printhtml(p->text, f);
	break;
	
    case CODE:
	printcode(p->text, f);
	break;
	
    case QUOTE:
    if (p->down) {
        p->down->easyNewline = p->easyNewline;
    }
	htmlify(p->down, p->ident ? "div" : "blockquote", p->ident, f);
	break;
	
    case UL:
    case OL:
    case AL:
	listdisplay(p->typ, p->down, f);
	break;

    case DL:
	definitionlist(p->down, f);
	break;

    case HR:
	Qstring("<hr />", f);
	break;

    case HDR:
	printheader(p, f);
	break;

    case TABLE:
	printtable(p, f);
	break;

    case SOURCE:
    if (p->down) {
        p->down->easyNewline = p->easyNewline;
    }
	htmlify(p->down, 0, 0, f);
	break;
	
    default:
	printblock(p, f, easyNewLine);
	break;
    }
    // MK HACK, copy easyNewLine
    Paragraph *pNext = p->next;
    if (pNext) {
        pNext->easyNewline = p->easyNewline;
    }
    return pNext;
}
Пример #7
0
main()
{
 int fl,o,i=1,j=0,tn,re,scr=1,k=1,l=0,m=0;
 char ex0,ch,are[9],cds[16];
 FILE *fp,*ft,*f;
 clrscr();
fp=fopen("pqr.txt","r");
f=fopen("zhid.txt","w");
printf("%c",128);
exit(0);
while(!eof(0))
{
  ch=fgetc(fp);
  fprintf(f,"%c",ch);
  printf("%d",ch);
}
exit(0);
fl=ftell(fp);
fseek(fp,-1,SEEK_END);
ex0=fgetc(fp);
printf("%c",ex0);
fseek(fp,fl,SEEK_SET);

 fscanf(fp,"%d",&n);
 printf("%d\n",n);
 tn=2*n-1;
 for(i=1;i<=n;i++)
 {
   ch=fgetc(fp);
   fscanf(fp,"%d",&a);
   tree[i+n][0]=a;
   ch=fgetc(fp);
   alpha[i]=ch;
   fscanf(fp,"%d",&a);
   tree[i+n][1]=a;
 }
 Rec(tn,0);
 printcode();

   while(ch!=' ')
 {
   ch=fgetc(fp);
   numvl=ch;
 }

 o=7;i=0;
 while(ch!=EOF)
 {
     o=7;
     ch=fgetc(fp);
     printf("%c",ch);
     if(ch==ex0) if(fgetc(fp)==EOF) break;
     else fseek(fp,-1L,SEEK_CUR);

     numvl=ch;
     if(numvl<0) numvl=256+numvl;
     while(numvl!=1)
	  {
	    re=numvl%2;
	    numvl/=2;
	    if(re==1) are[o--]='1';
	    else are[o--]='0';
	  }
	  are[o--]='1';
     while(o!=-1)
	    are[o--]='0';

     are[8]='\x0';
     j=0;
     while(are[j])
	  {
	    cds[i++]=are[j++];
	  }
     cds[i++]='\x0';
     i=0;l=0;

     while(cds[l]!='\x0')
	  {
	    k=1;
	    are[i++]=cds[l];
	    are[i]='\x0';
	    l++;
	    while(k!=n+1)
		{
		   scr=strcmp(are,codes[k]);
		   k++;
		   if(scr==0)
		     {  m=l;
			k--;
			printf("%c",alpha[k]);
			i=0;break;
		     }
		}
	  } i=0;
     while(cds[m]!='\x0')
	  {
	     cds[i++]=cds[m++];
	  }
	  cds[i]='\x0';
 }
 getch();
}