Beispiel #1
0
functnode *newfunct(char *string, int value)
{
  functnode *ptr = functtable;

  if (findsymbol(string) != -1)
  {
    char buf[80];
    sprintf(buf, "function %s defined twice", string);
    yyerror(buf);
    return ptr;
  }

  if (debug)
  {
    if (value >= 0)
    {
      printf("external function %s defined at $%04x\n", string, value);
    }
    else
    {
      printf("internal function %s defined\n", string);
    }
  }
  if (!functtable)
  {
    functtable = (functnode *)malloc(sizeof (functnode));
    ptr = functtable;
    ptr->string = strdup(string);
    ptr->value = value;
    ptr->next = NULL;
    return ptr;
  }

  while (ptr->next)
  {
    ptr = ptr->next;
  }

  ptr->next = (functnode *)malloc(sizeof (functnode));
  ptr = ptr->next;
  ptr->string = strdup(string);
  ptr->value = value;
  ptr->next = NULL;
  return ptr;
}
Beispiel #2
0
/*
 * Globalize a symbol (export if defined, import if not)
 */
void 
sym_Global(char *tzSym)
{
	if (nPass == 2) {
		/* only globalize symbols in pass 2 */
		struct sSymbol *nsym;

		nsym = findsymbol(tzSym, 0);

		if ((nsym == NULL) || ((nsym->nType & SYMF_DEFINED) == 0)) {
			if (nsym == NULL)
				nsym = createsymbol(tzSym);

			if (nsym)
				nsym->nType |= SYMF_IMPORT;
		} else {
			if (nsym)
				nsym->nType |= SYMF_EXPORT;
		}
	}
}
        void putsymbol(char *symbol,int org,int unique,int line)
        {
                struct node_t *node;

                if(unique)
                        if((node=findsymbol(symbols,symbol))!=NULL)
                        {
                                printf("redef'd symbol %s in line %d\n",symbol,line);
                                ok=0;
                                return;
                        }
                ++numsymbols;

                *alloc=(struct node_t*)malloc(sizeof(struct node_t));
                node=*alloc;
                node->s=malloc(strlen(symbol)+1);
                strcpy(node->s,symbol);
                node->i=org;
                node->p=NULL;
                alloc=&(node->p);
        }
Beispiel #4
0
/*
 * Add a string equated symbol
 */
void 
sym_AddString(char *tzSym, char *tzValue)
{
	struct sSymbol *nsym;

	if ((nsym = findsymbol(tzSym, NULL)) != NULL) {
		if (nsym->nType & SYMF_DEFINED) {
			yyerror("'%s' already defined", tzSym);
		}
	} else
		nsym = createsymbol(tzSym);

	if (nsym) {
		if ((nsym->pMacro = malloc(strlen(tzValue) + 1)) != NULL)
			strcpy(nsym->pMacro, tzValue);
		else
			fatalerror("No memory for stringequate");
		nsym->nType |= SYMF_STRING | SYMF_DEFINED;
		nsym->ulMacroSize = strlen(tzValue);
		nsym->pScope = NULL;
	}
}
Beispiel #5
0
/*
 * Add an equated symbol
 */
void 
sym_AddEqu(char *tzSym, SLONG value)
{
	if ((nPass == 1)
	    || ((nPass == 2) && (sym_isDefined(tzSym) == 0))) {
		/* only add equated symbols in pass 1 */
		struct sSymbol *nsym;

		if ((nsym = findsymbol(tzSym, NULL)) != NULL) {
			if (nsym->nType & SYMF_DEFINED) {
				yyerror("'%s' already defined", tzSym);
			}
		} else
			nsym = createsymbol(tzSym);

		if (nsym) {
			nsym->nValue = value;
			nsym->nType |= SYMF_EQU | SYMF_DEFINED | SYMF_CONST;
			nsym->pScope = NULL;
		}
	}
}
Beispiel #6
0
/*
 * Return a constant symbols value
 */
ULONG 
sym_GetConstantValue(char *s)
{
	struct sSymbol *psym, *pscope;

	if (*s == '.')
		pscope = pScope;
	else
		pscope = NULL;

	if ((psym = findsymbol(s, pscope)) != NULL) {
		if (psym->nType & SYMF_CONST)
			return (getvaluefield(psym));
		else {
			fatalerror("Expression must have a constant value");
		}
	} else {
		yyerror("'%s' not defined", s);
	}

	return (0);
}
Beispiel #7
0
/*
 * Determine if a symbol has been defined
 */
ULONG 
sym_isConstDefined(char *tzName)
{
	struct sSymbol *psym, *pscope;

	if (*tzName == '.')
		pscope = pScope;
	else
		pscope = NULL;

	psym = findsymbol(tzName, pscope);

	if (psym && (psym->nType & SYMF_DEFINED)) {
		if (psym->
		    nType & (SYMF_EQU | SYMF_SET | SYMF_MACRO | SYMF_STRING)) {
			return (1);
		} else {
			fatalerror("'%s' is not allowed as argument to the "
			    "DEF function", tzName);
		}
	}
	return (0);
}
Beispiel #8
0
static unsigned int findmodulesymbol(unsigned int count, char *symbolname)
{

    unsigned int length = memory_findbyte(symbolname, count, '_') - 1;
    unsigned int offset = 0;
    unsigned int address;
    char module[32];

    offset += memory_write(module, 32, symbolname, length, offset);
    offset += memory_write(module, 32, ".ko", 4, offset);

    if (!file_walkfrom(CALL_L2, CALL_L1, module))
        return 0;

    file_open(CALL_L2);

    address = findsymbol(CALL_L2, count, symbolname);

    file_close(CALL_L2);

    return address;

}
Beispiel #9
0
/*
 * Add a macro definition
 */
void 
sym_AddMacro(char *tzSym)
{
	if ((nPass == 1)
	    || ((nPass == 2) && (sym_isDefined(tzSym) == 0))) {
		/* only add macros in pass 1 */
		struct sSymbol *nsym;

		if ((nsym = findsymbol(tzSym, NULL)) != NULL) {
			if (nsym->nType & SYMF_DEFINED) {
				yyerror("'%s' already defined", tzSym);
			}
		} else
			nsym = createsymbol(tzSym);

		if (nsym) {
			nsym->nValue = nPC;
			nsym->nType |= SYMF_MACRO | SYMF_DEFINED;
			nsym->pScope = NULL;
			nsym->ulMacroSize = ulNewMacroSize;
			nsym->pMacro = tzNewMacro;
		}
	}
}
Beispiel #10
0
/*
 * Find a macro by name
 */
struct sSymbol *
sym_FindMacro(char *s)
{
	return (findsymbol(s, NULL));
}
Beispiel #11
0
//
// OSD_HandleKey() -- Handles keyboard input when capturing input.
// 	Returns 0 if the key was handled internally, or the scancode if it should
// 	be passed on to the game.
//
int OSD_HandleKey(int sc, int press)
{
	char ch;
	int i,j;
	symbol_t *tabc = NULL;
	static symbol_t *lastmatch = NULL;
	
	if (!osdinited) return sc;

	if (sc == osdkey) {
		if (press) {
			OSD_ShowDisplay(osdvisible ^ 1);
			bflushchars();
		}
		return 0;//sc;
	} else if (!osdvisible) {
		return sc;
	}

	if (!press) {
		if (sc == 42 || sc == 54) // shift
			osdeditshift = 0;
		if (sc == 29 || sc == 157)	// control
			osdeditcontrol = 0;
		return 0;//sc;
	}

	keytime = gettime();

	if (sc != 15) lastmatch = NULL;		// tab

	while ( (ch = bgetchar()) ) {
		if (ch == 1) {	// control a. jump to beginning of line
		} else if (ch == 2) {	// control b, move one character left
		} else if (ch == 5) {	// control e, jump to end of line
		} else if (ch == 6) {	// control f, move one character right
		} else if (ch == 8 || ch == 127) {	// control h, backspace
			if (!osdeditcursor || !osdeditlen) return 0;
			if (!osdovertype) {
				if (osdeditcursor < osdeditlen)
					Bmemmove(osdeditbuf+osdeditcursor-1, osdeditbuf+osdeditcursor, osdeditlen-osdeditcursor);
				osdeditlen--;
			}
			osdeditcursor--;
			if (osdeditcursor<osdeditwinstart) osdeditwinstart--,osdeditwinend--;
		} else if (ch == 9) {	// tab
			if (!lastmatch) {
				for (i=osdeditcursor;i>0;i--) if (osdeditbuf[i-1] == ' ') break;
				for (j=0;osdeditbuf[i] != ' ' && i < osdeditlen;j++,i++)
					osdedittmp[j] = osdeditbuf[i];
				osdedittmp[j] = 0;

				if (j > 0)
					tabc = findsymbol(osdedittmp, NULL);
			} else {
				tabc = findsymbol(osdedittmp, lastmatch->next);
				if (!tabc && lastmatch)
					tabc = findsymbol(osdedittmp, NULL);	// wrap
			}

			if (tabc) {
				for (i=osdeditcursor;i>0;i--) if (osdeditbuf[i-1] == ' ') break;
				osdeditlen = i;
				for (j=0;tabc->name[j] && osdeditlen <= EDITLENGTH;i++,j++,osdeditlen++)
					osdeditbuf[i] = tabc->name[j];
				osdeditcursor = osdeditlen;
				osdeditwinend = osdeditcursor;
				osdeditwinstart = osdeditwinend-editlinewidth;
				if (osdeditwinstart<0) {
					osdeditwinstart=0;
					osdeditwinend = editlinewidth;
				}
			
				lastmatch = tabc;
			}
		} else if (ch == 11) {	// control k, delete all to end of line
		} else if (ch == 12) {	// control l, clear screen
		} else if (ch == 13) {	// control m, enter
			if (osdeditlen>0) {
				osdeditbuf[osdeditlen] = 0;
				Bmemmove(osdhistorybuf[1], osdhistorybuf[0], (HISTORYDEPTH-1)*(EDITLENGTH+1));
				Bmemmove(osdhistorybuf[0], osdeditbuf, EDITLENGTH+1);
				if (osdhistorysize < HISTORYDEPTH) osdhistorysize++;
				if (osdexeccount == HISTORYDEPTH)
					OSD_Printf("Command Buffer Warning: Failed queueing command "
							"for execution. Buffer full.\n");
				else
					osdexeccount++;
				osdhistorypos=-1;
			}

			osdeditlen=0;
			osdeditcursor=0;
			osdeditwinstart=0;
			osdeditwinend=editlinewidth;
		} else if (ch == 16) {	// control p, previous (ie. up arrow)
		} else if (ch == 20) {	// control t, swap previous two chars
		} else if (ch == 21) {	// control u, delete all to beginning
			if (osdeditcursor>0 && osdeditlen) {
				if (osdeditcursor<osdeditlen)
					Bmemmove(osdeditbuf, osdeditbuf+osdeditcursor, osdeditlen-osdeditcursor);
				osdeditlen-=osdeditcursor;
				osdeditcursor = 0;
				osdeditwinstart = 0;
				osdeditwinend = editlinewidth;
			}
		} else if (ch == 23) {	// control w, delete one word back
			if (osdeditcursor>0 && osdeditlen>0) {
				i=osdeditcursor;
				while (i>0 && osdeditbuf[i-1]==32) i--;
				while (i>0 && osdeditbuf[i-1]!=32) i--;
				if (osdeditcursor<osdeditlen)
					Bmemmove(osdeditbuf+i, osdeditbuf+osdeditcursor, osdeditlen-osdeditcursor);
				osdeditlen -= (osdeditcursor-i);
				osdeditcursor = i;
				if (osdeditcursor < osdeditwinstart) {
					osdeditwinstart=osdeditcursor;
					osdeditwinend=osdeditwinstart+editlinewidth;
				}
			}
		} else if (ch >= 32) {	// text char
			if (!osdovertype && osdeditlen == EDITLENGTH)	// buffer full, can't insert another char
				return 0;

			if (!osdovertype) {
				if (osdeditcursor < osdeditlen) 
					Bmemmove(osdeditbuf+osdeditcursor+1, osdeditbuf+osdeditcursor, osdeditlen-osdeditcursor);
				osdeditlen++;
			} else {
				if (osdeditcursor == osdeditlen)
					osdeditlen++;
			}
			osdeditbuf[osdeditcursor] = ch;
			osdeditcursor++;
			if (osdeditcursor>osdeditwinend) osdeditwinstart++,osdeditwinend++;
		}
	}

	if (sc == 15) {		// tab
	} else if (sc == 1) {		// escape
		OSD_ShowDisplay(0);
	} else if (sc == 201) {	// page up
		if (osdhead < osdlines-1)
			osdhead++;
	} else if (sc == 209) {	// page down
		if (osdhead > 0)
			osdhead--;
	} else if (sc == 199) {	// home
		if (osdeditcontrol) {
			osdhead = osdlines-1;
		} else {
			osdeditcursor = 0;
			osdeditwinstart = osdeditcursor;
			osdeditwinend = osdeditwinstart+editlinewidth;
		}
	} else if (sc == 207) {	// end
		if (osdeditcontrol) {
			osdhead = 0;
		} else {
			osdeditcursor = osdeditlen;
			osdeditwinend = osdeditcursor;
			osdeditwinstart = osdeditwinend-editlinewidth;
			if (osdeditwinstart<0) {
				osdeditwinstart=0;
				osdeditwinend = editlinewidth;
			}
		}
	} else if (sc == 210) {	// insert
		osdovertype ^= 1;
	} else if (sc == 203) {	// left
		if (osdeditcursor>0) {
			if (osdeditcontrol) {
				while (osdeditcursor>0) {
					if (osdeditbuf[osdeditcursor-1] != 32) break;
					osdeditcursor--;
				}
				while (osdeditcursor>0) {
					if (osdeditbuf[osdeditcursor-1] == 32) break;
					osdeditcursor--;
				}
			} else osdeditcursor--;
		}
		if (osdeditcursor<osdeditwinstart)
			osdeditwinend-=(osdeditwinstart-osdeditcursor),
			osdeditwinstart-=(osdeditwinstart-osdeditcursor);
	} else if (sc == 205) {	// right
		if (osdeditcursor<osdeditlen) {
			if (osdeditcontrol) {
				while (osdeditcursor<osdeditlen) {
					if (osdeditbuf[osdeditcursor] == 32) break;
					osdeditcursor++;
				}
				while (osdeditcursor<osdeditlen) {
					if (osdeditbuf[osdeditcursor] != 32) break;
					osdeditcursor++;
				}
			} else osdeditcursor++;
		}
		if (osdeditcursor>=osdeditwinend)
			osdeditwinstart+=(osdeditcursor-osdeditwinend),
			osdeditwinend+=(osdeditcursor-osdeditwinend);
	} else if (sc == 200) {	// up
		if (osdhistorypos < osdhistorysize-1) {
			osdhistorypos++;
			memcpy(osdeditbuf, osdhistorybuf[osdhistorypos], EDITLENGTH+1);
			osdeditlen = osdeditcursor = 0;
			while (osdeditbuf[osdeditcursor]) osdeditlen++, osdeditcursor++;
			if (osdeditcursor<osdeditwinstart) {
				osdeditwinend = osdeditcursor;
				osdeditwinstart = osdeditwinend-editlinewidth;
				
				if (osdeditwinstart<0)
					osdeditwinend-=osdeditwinstart,
					osdeditwinstart=0;
			} else if (osdeditcursor>=osdeditwinend)
				osdeditwinstart+=(osdeditcursor-osdeditwinend),
				osdeditwinend+=(osdeditcursor-osdeditwinend);
		}
	} else if (sc == 208) {	// down
		if (osdhistorypos >= 0) {
			if (osdhistorypos == 0) {
				osdeditlen=0;
				osdeditcursor=0;
				osdeditwinstart=0;
				osdeditwinend=editlinewidth;
				osdhistorypos = -1;
			} else {
				osdhistorypos--;
				memcpy(osdeditbuf, osdhistorybuf[osdhistorypos], EDITLENGTH+1);
				osdeditlen = osdeditcursor = 0;
				while (osdeditbuf[osdeditcursor]) osdeditlen++, osdeditcursor++;
				if (osdeditcursor<osdeditwinstart) {
					osdeditwinend = osdeditcursor;
					osdeditwinstart = osdeditwinend-editlinewidth;
					
					if (osdeditwinstart<0)
						osdeditwinend-=osdeditwinstart,
						osdeditwinstart=0;
				} else if (osdeditcursor>=osdeditwinend)
					osdeditwinstart+=(osdeditcursor-osdeditwinend),
					osdeditwinend+=(osdeditcursor-osdeditwinend);
			}
		}
	} else if (sc == 42 || sc == 54) {	// shift
		osdeditshift = 1;
	} else if (sc == 29 || sc == 157) {	// control
		osdeditcontrol = 1;
	} else if (sc == 58) {	// capslock
		osdeditcaps ^= 1;
	} else if (sc == 28 || sc == 156) {	// enter
	} else if (sc == 14) {		// backspace
	} else if (sc == 211) {	// delete
		if (osdeditcursor == osdeditlen || !osdeditlen) return 0;
		if (osdeditcursor <= osdeditlen-1) Bmemmove(osdeditbuf+osdeditcursor, osdeditbuf+osdeditcursor+1, osdeditlen-osdeditcursor-1);
		osdeditlen--;
	}
	
	return 0;
}
        int main(int argc, char **argv)
        {
                int org=0;
                char *line;
                int i,j;
                int sourceline=0;

                char skout[500],pkout[500];

                //printf("argc=%d\n",argc);

                if(argc!=3)
                {
                        printf("usage: %s <in> <out>\n",argv[0]);
                        exit(0);
                }

                sprintf(skout,"%s.hcrypt_sk",argv[2]);
                sprintf(pkout,"%s.hcrypt_pk",argv[2]);

                fhe_pk_init(pk);
                fhe_sk_init(sk);

               // fhe_pk_loadkey(pk,argv[3]);
                //fhe_pk_print(pk);

                puts("keygen");
                fhe_keygen(pk,sk);
                fhe_pk_store(pk,pkout);
                fhe_sk_store(sk,skout);

                printf("wrote secret key: %s\n",skout);
                printf("wrote public key: %s\n",pkout);

                symbols=NULL;
                alloc=&symbols;

                FILE *r=NULL;
                FILE *w=NULL;
                //BufferedReader r=new BufferedReader(new FileReader("/tmp/test.asm"));
                r=fopen(argv[1],"r");
                if(r==NULL)
                {
                        puts("source error");
                        return 8;
                }
                //BufferedWriter w=new BufferedWriter(new FileWriter("/tmp/test.obj"));
                w=fopen(argv[2],"w");
                if(w==NULL)
                {
                        puts("target error");
                        return 8;
                }

                //System.out.println("PASS 1");
                puts("pass 1");

                line=(char*)malloc(1024);

                //HashMap<String,Integer> labels=new HashMap<String,Integer>();

                while(!feof(r))
                {
                        char *token, *tokens[100];
                        //String label=null;
                        char *label;
                        int numtokens;
                        //String line=r.readLine();
                        ++sourceline;
                        fgets(line,100,r);


                        if(*line==0)
                                break;

                        if(strstr(line,"INITAC")||strstr(line,"INITPC"))
                                continue;

                        //StringTokenizer st=new StringTokenizer(line," \t\n;");

                        numtokens=0;
                        token=strtok(line," \n\t");
                        while(token!=NULL)
                        {
                                tokens[numtokens]=token;
                                token=strtok(NULL," \n\t");
                                ++numtokens;
                        }

                        label=tokens[0];

                        if(numtokens==0)
                                continue;

                        if(numtokens==2)
                        {
                                if(!(*line==' '||*line=='\t'))
                                {
                                        //++label;
                                        //labels.put(label, new Integer(org));
                                        //printf("put symbol %s=%d\n",label,org);
                                        putsymbol(label,org,1,sourceline);
                                }
                        }
                        else if(numtokens>2)
                        {
                                //++label;
                                //labels.put(label, new Integer(org));
                                //printf("put symbol %s=%d\n",label,org);
                                putsymbol(label,org,1,sourceline);
                        }
                        org++;
                }
                //printlist(symbols);
                printf(" %d symbols\n %d command words\n",numsymbols,org);


                //XXX
                //System.out.println("PASS 2");
                puts("pass 2");
                rewind(r);

                sourceline=0;
                //r=new BufferedReader(new FileReader("test.asm"));

                while(!feof(r))
                {
                        char *token, *tokens[100];
                        //String label=null;
                        char *label,*opcode,*operand;
                        int numtokens,symboladdress,cmd;
                        char line0;
                        struct node_t *search;
                        //String label=null;

                        ++sourceline;
                        fgets(line,100,r);
                        if(feof(r))
                                break;

                        if(*line==0)
                                break;

                        line0=*line;
                        numtokens=0;
                        token=strtok(line," \n\t");
                        while(token!=NULL)
                        {
                                tokens[numtokens]=token;
                                token=strtok(NULL," \n\t");
                                ++numtokens;
                        }

                        //StringTokenizer st=new StringTokenizer(line," \n\t;");
                        if(numtokens==0)
                                continue;

                        if(!strcmp(tokens[0],"INITAC"))
                        {
                                search=findsymbol(symbols,tokens[1]);

                                if(search!=NULL)
                                {
                                        symboladdress=search->i;
                                }
                                else
                                {
                                        symboladdress=atoi(tokens[1]);

                                        if(symboladdress==0&&*tokens[1]!='0')
                                        {
                                                ok=0;
                                                printf("undef'd symbol %s in line %d\n",tokens[1],sourceline);
                                        }
                                }
                                for(i=1;i<256;i*=2)
                                {
                                        if(symboladdress&i)
                                                fhe_encrypt(cipher,pk,1);
                                        else
                                                fhe_encrypt(cipher,pk,0);

                                        gmp_fprintf(w,"%Zd\n",cipher);
                                }
                                continue;
                        }

                        if(!strcmp(tokens[0],"INITPC"))
                        {
                                search=findsymbol(symbols,tokens[1]);

                                if(search!=NULL)
                                {
                                        symboladdress=search->i;
                                }
                                else
                                {
                                        symboladdress=atoi(tokens[1]);

                                        if(symboladdress==0&&*tokens[1]!='0')
                                        {
                                                ok=0;
                                                printf("undef'd symbol %s in line %d\n",tokens[1],sourceline);
                                        }
                                }

                                for(i=1;i<256;i*=2)
                                {
                                        if(symboladdress&i)
                                                fhe_encrypt(cipher,pk,1);
                                        else
                                                fhe_encrypt(cipher,pk,0);

                                        gmp_fprintf(w,"%Zd\n",cipher);
                                }

                                continue;
                        }



                        label="";
                        opcode="";
                        operand="";

                        if(line0==' '||line0=='\t')
                        {
                                opcode=tokens[0];
                                if(numtokens==2)
                                        operand=tokens[1];
                        }
                        else
                        {
                                label=tokens[0];
                                opcode=tokens[1];
                                if(numtokens>2)
                                        operand=tokens[2];
                        }

                        cmd=0;

                        if(!strcmp(opcode,".BD"))
                                cmd=100;
                        if(!strcmp(opcode,"STa"))
                                cmd=15;
                        if(!strcmp(opcode,"L"))
                                cmd=14;
                        if(!strcmp(opcode,"ROL"))
                                cmd=13;
                        if(!strcmp(opcode,"ROR"))
                                cmd=12;
                        if(!strncmp(opcode,"ADD",3))
                                cmd=11;
                        if(!strcmp(opcode,"CLC"))
                                cmd=10;
                        if(!strcmp(opcode,"SEC"))
                                cmd=9;
                        if(!strncmp(opcode,"XOR",3))
                                cmd=8;
                        if(!strncmp(opcode,"AND",3))
                                cmd=7;
                        if(!strncmp(opcode,"OR",2))
                                cmd=6;
                        if(!strcmp(opcode,"BEQ"))
                                cmd=5;
                        if(!strcmp(opcode,"J"))
                                cmd=4;
                        if(!strcmp(opcode,"La"))
                                cmd=3;
                        if(!strcmp(opcode,"BMI"))
                                cmd=2;
                        if(!strncmp(opcode,"CMP",3))
                                cmd=1;

                        if(opcode[strlen(opcode)-1]=='a')
                                cmd+=16;

                        if(*operand==0)
                                operand="0";

                        search=findsymbol(symbols,operand);
                        if(search!=NULL)
                        {
                                symboladdress=search->i;
                        }
                        else
                        {
                                symboladdress=atoi(operand);

                                if(symboladdress==0&&*operand!='0'&&cmd<100)
                                {
                                        ok=0;
                                        printf("undef'd symbol %s in line %d\n",operand,sourceline);
                                }
                        }

                        //printf("%s,%s,%s (%d)\n",*label?label:"-",opcode,operand,symboladdress);

                        //System.out.println(label+","+opcode+","+operand+"("+lookup+")");

                        //int[] operation=null;



                        /*
                        operation=Function.encode(5, cmd);

                        int[] argument=Function.encode(8, Integer.parseInt(lookup!=null?lookup:operand));

                        for(int i=0;i<8;i++)
                        {
                                System.out.print(hex(argument[i])+" ");
                                w.write(hex(argument[i])+" ");
                        }
                        for(int i=0;i<5;i++)
                        {
                                System.out.print(hex(operation[i])+" ");
                                w.write(hex(operation[i])+" ");
                        }
                        System.out.println("\t\t"+line);
                        w.write("\n");
                        */
                        //printf("%d %d -> ",cmd,symboladdress);

                        if(cmd<100)
                        {
                                for(i=1;i<256;i*=2)
                                {
                                        if(symboladdress&i)
                                                fhe_encrypt(cipher,pk,1);
                                        else
                                                fhe_encrypt(cipher,pk,0);

                                        gmp_fprintf(w,"%Zd\n",cipher);
                                }

                                for(i=1;i<32;i*=2)
                                {
                                        if(cmd&i)
                                                fhe_encrypt(cipher,pk,1);
                                        else
                                                fhe_encrypt(cipher,pk,0);

                                        gmp_fprintf(w,"%Zd\n",cipher);
                                }
                        }
                        else
                        {
                                if(cmd==100) //.BD binary data
                                {
                                        if(strlen(operand)!=13)
                                        {
                                                printf("binary dataword length mismatch in line %d\n",sourceline);
                                        }
                                        for(i=0;i<13;i++)
                                        {
                                                if(operand[i]!='0'&&operand[i]!='1')
                                                {
                                                        printf("binary dataword syntax error in line %d\n",sourceline);
                                                }
                                                if(operand[i]=='0')
                                                        fhe_encrypt(cipher,pk,0);
                                                else
                                                        fhe_encrypt(cipher,pk,1);

                                                gmp_fprintf(w,"%Zd\n",cipher);
                                        }
                                }
                        }
                        //printf(".\n");
                }

                printf("---- reference table start ----\n");
                printlist(symbols);
                printf("---- reference table end   ----\n");
                //XXX
                fclose(w);
                fclose(r);
                freelist(symbols);
                fhe_pk_clear(pk);
                mpz_clear(cipher);

                printf("%s\n",ok?"ok":"errors");

                return 0;
        }
newtime(char *filename)
{
	struct sym	timez, name_st, name_dy, dayflag;
	struct header	head;
	register int	i, fdes;
	int		adr, secs;
	char		std[4], dyl[4];

	if ((fdes = openheader(&head, filename)) < 0)
		return (-1);

	bmove("_timezon", timez.symname, 8);
	bmove("_tzname\0", name_st.symname, 8);
	bmove("_dayligh", dayflag.symname, 8);

	/* pick up addresses from symbol table */
	i = findsymbol(&head, fdes, &timez);
	i |= findsymbol(&head, fdes, &name_st);
	i |= findsymbol(&head, fdes, &dayflag);

	if (i) {
		printf("File %s does not need to be corrected\n", filename);
		close(fdes);
		return (-2);
	}

	/* form entries for pointer to "PST" and "PDT" */
	i = getvalue(&head, fdes, &name_st, &adr, 2);
	name_st.value += 2;
	i |= getvalue(&head, fdes, &name_st, &name_dy.value, 2);
	name_dy.type = name_st.type;
	name_st.value = adr;

	if (i) {
		printf("can't find pointers to timezone names in %s\n", filename);
		close(fdes);
		return (-3);
	}

	/* now print out current values */
	i = getvalue(&head, fdes, &timez, &secs, 2);
	i |= getvalue(&head, fdes, &name_st, std, 4);
	i |= getvalue(&head, fdes, &name_dy, dyl, 4);
	i |= getvalue(&head, fdes, &dayflag, &adr, 2);

	if (i) {
		printf("one or more symbols cannot be read from %s\n", filename);
		close(fdes);
		return (-4);
	}

	pr_values(filename, secs, std, dyl, adr);

	if (!Noupdate) {
		if (putvalue(&head, fdes, &timez, &timezone, 2)
			|| putvalue(&head, fdes, &name_st, tzname[0], 4)
			|| putvalue(&head, fdes, &name_dy, tzname[1], 4)
			|| putvalue(&head, fdes, &dayflag, &daylight, 2)) {
			printf("cannot update %s with new values\n", filename);
			close(fdes);
			return (-2);
		}
		else
			printf("File %s updated.\n", filename);
	}


	close(fdes);

	return (0);
}