Пример #1
0
static void hexify (unsigned char * buf, int n) 
{
  int i;
  for ( i = n-1; i >= 0; i-- ) {
	unsigned char c = buf[i];
    buf[2*i] = itoh(c / 16);
    buf[2*i + 1] = itoh(c & 0xF);
  }

  /* Null terminate */
  buf[2*n] = '\0';
}
Пример #2
0
void TimerHandler(struct regs *r)
{
	if(__ticks > 0) __ticks--;
    int i;
    char buffer[12];
    for(i = 0; i < 256; i++)
    {   
        if(__timers[i].schedCallback != null && __timers[i].ticks > 0)
        {

                
            if(__timers[i].ticks == 0)
            {
                itoa(i, buffer);
                print("Timer Firing: ");
                print(buffer);
                print(" : ");
                itoh((unsigned int)__timers[i].schedCallback, buffer);
                print(buffer);
                print("\n");
                __timers[i].schedCallback(__timers[i].param);
            }
        }
    }
}
Пример #3
0
void
print_uint(uint16_t uart, uint32_t x, int ndigits)

{
  char	buf[10];
  uart_send_str(uart,itoh(buf,x)+(8-ndigits));
}
Пример #4
0
//take a 3 item normalized float array and convert it into a hex string like #AAFF88
void ConfigSettings::nftoh(float *array, char *string){
	int intarray[3];
	for (int i=0; i<3; i++){
		intarray[i]=(int)(array[i]*255);
	}
	itoh(intarray, string);
}
Пример #5
0
//-------------------------------------------------------------------------
// y-func : get stream info
//-------------------------------------------------------------------------
std::string  CNeutrinoYParser::func_get_current_stream_info(CyhookHandler *hh, std::string para)
{
	int bitInfo[10];
	CZapitClient::CCurrentServiceInfo serviceinfo;

	serviceinfo = NeutrinoAPI->Zapit->getCurrentServiceInfo();
	hh->ParamList["onid"] = itoh(serviceinfo.onid);
	hh->ParamList["sid"] = itoh(serviceinfo.sid);
	hh->ParamList["tsid"] = itoh(serviceinfo.tsid);
	hh->ParamList["vpid"] = itoh(serviceinfo.vpid);
	hh->ParamList["apid"] = itoh(serviceinfo.apid);
	hh->ParamList["vtxtpid"] = (serviceinfo.vtxtpid != 0)?itoh(serviceinfo.vtxtpid):"nicht verf&uuml;gbar";
	hh->ParamList["pmtpid"] = (serviceinfo.pmtpid != 0)?itoh(serviceinfo.pmtpid):"nicht verf&uuml;gbar";
	hh->ParamList["tsfrequency"] = string_printf("%d.%d MHz", serviceinfo.tsfrequency/1000, serviceinfo.tsfrequency%1000);
	hh->ParamList["polarisation"] = serviceinfo.polarisation==1?"h":"v";
	hh->ParamList["ServiceName"] = NeutrinoAPI->GetServiceName(live_channel_id);//NeutrinoAPI->Zapit->getCurrentServiceID());
	NeutrinoAPI->GetStreamInfo(bitInfo);
	
	hh->ParamList["VideoFormat"] = string_printf("%d x %d", bitInfo[0], bitInfo[1] );
	hh->ParamList["BitRate"] = string_printf("%d\n", bitInfo[4]*50);
	
	switch ( bitInfo[2] ) //format
	{
		case 2: hh->ParamList["AspectRatio"] = "4:3"; break;
		case 3: hh->ParamList["AspectRatio"] = "16:9"; break;
		case 4: hh->ParamList["AspectRatio"] = "2.21:1"; break;
		default: hh->ParamList["AspectRatio"]= "unknown"; break;
	}

	switch ( bitInfo[3] ) //fps
	{
		case 3: hh->ParamList["FPS"] = "25"; break;
		case 6: hh->ParamList["FPS"] = "50"; break;
		default: hh->ParamList["FPS"]= "unknown";
	}

	if (!bitInfo[7]) hh->ParamList["AudioType"]="unknown";
	else {
		const char* layernames[4]={"res","III","II","I"};
		const char* sampfreqnames[4]={"44,1k","48k","32k","res"};
		const char* modenames[4]={"stereo","joint_st","dual_ch","single_ch"};

		long header = bitInfo[7];

		unsigned char layer =	(header>>17)&3;
		unsigned char sampfreq =(header>>10)&3;
		unsigned char mode =	(header>> 6)&3;
		unsigned char copy =	(header>> 3)&1;

		hh->ParamList["AudioType"] = 
			string_printf("%s (%s/%s) %s", modenames[mode],	sampfreqnames[sampfreq],
				layernames[layer], copy?"c":"");
	}
	return "";
}
Пример #6
0
void
print_cpu_info(uint16_t uart)

{
  char	buf[100];
  int	i;

  for (i = 0; i < 3; i++) {
    buf_100[0] = 0;
    strcat(buf_100,"UID ");
    strcat(buf_100,itoh(buf,i)+7);
    strcat(buf_100,": ");
    strcat(buf_100,itoh(buf,UNIQUE_ID->UID[i]));
    strcat(buf_100,"\r\n");
    uart_send_str(uart,buf_100);
  }
  buf_100[0] = 0;
  strcat(buf_100,"MEMSIZE ");
  strcat(buf_100,itoh(buf,MEMSIZE)+4);
  strcat(buf_100,"\r\n");
  uart_send_str(uart,buf_100);
}
Пример #7
0
void InitTimer(int frequency)
{
	int divisor = 1193180 / frequency;
	out(0x43, 0x36);
	out(0x40, (unsigned char)(divisor& 0xFF));
	out(0x40, (unsigned char)(divisor >> 8));
    __ticks = 0;
    __timers = kmalloc(sizeof(Timer)*256);
    memset(__timers, 0, sizeof(Timer)*256);
	char buffer[12];
    itoh(__timers, buffer);
    print("Timers allocated at: ");
    print(buffer);
    print("\n");
    IRQInstallRoutine(0,&TimerHandler);
}
Пример #8
0
/*  setlabel
 *
 *  Post a code label (specified as a number), on a new line.
 */
SC_FUNC void setlabel(int number)
{
  assert(number>=0);
  stgwrite("l.");
  stgwrite((char *)itoh(number));
  /* To assist verification of the assembled code, put the address of the
   * label as a comment. However, labels that occur inside an expression
   * may move (through optimization or through re-ordering). So write the
   * address only if it is known to accurate.
   */
  if (!staging) {
    stgwrite("\t\t; ");
    outval(code_idx,TRUE,FALSE);
  } /* if */
  stgwrite("\n");
}
Пример #9
0
void sh_memDump(char* params){
	// textDump pointer length
	int i;
	for(i=0;i<strLen(params);i++){
		if(params[i] == ' ') break;
	}
	char substr[i+1];
	memCopy(params,substr,i);
	substr[i] = 0;
	char* pointer = (char*) ((int*)strToInt(substr));
	char substr2[strLen(params)-i];
	memCopy(params+i+1,substr2,strLen(params)-i);
	int length = strToInt(substr2);
	char hex[3];
	hex[2] = 0;
	for(i=0;i<length;i++){
		itoh(pointer[i], hex);
		ttprint(hex);
		ttprint(" ");
	}
	ttprint("\n");
}
Пример #10
0
//-------------------------------------------------------------------------
// y-func : get stream info
//-------------------------------------------------------------------------
std::string  CNeutrinoYParser::func_get_current_stream_info(CyhookHandler *hh, std::string)
{
	CZapitClient::CCurrentServiceInfo serviceinfo;

	serviceinfo = NeutrinoAPI->Zapit->getCurrentServiceInfo();
	hh->ParamList["onid"] = itoh(serviceinfo.onid);
	hh->ParamList["sid"] = itoh(serviceinfo.sid);
	hh->ParamList["tsid"] = itoh(serviceinfo.tsid);
	hh->ParamList["vpid"] = itoh(serviceinfo.vpid);
	hh->ParamList["apid"] = itoh(serviceinfo.apid);
	hh->ParamList["vtxtpid"] = (serviceinfo.vtxtpid != 0)?itoh(serviceinfo.vtxtpid):"not available";
	hh->ParamList["pmtpid"] = (serviceinfo.pmtpid != 0)?itoh(serviceinfo.pmtpid):"not available";
	hh->ParamList["pcrpid"] = (serviceinfo.pcrpid != 0)?itoh(serviceinfo.pcrpid):"not available";
	hh->ParamList["tsfrequency"] = string_printf("%d.%d MHz", serviceinfo.tsfrequency/1000, serviceinfo.tsfrequency%1000);
	hh->ParamList["polarisation"] = serviceinfo.polarisation==1?"h":"v";
	hh->ParamList["ServiceName"] = NeutrinoAPI->GetServiceName(CZapit::getInstance()->GetCurrentChannelID());
	hh->ParamList["VideoFormat"] = NeutrinoAPI->getVideoResolutionAsString();
//	hh->ParamList["BitRate"] = NeutrinoAPI->getVideoFramerateAsString();
	hh->ParamList["AspectRatio"] = NeutrinoAPI->getVideoAspectRatioAsString();
	hh->ParamList["FPS"] = NeutrinoAPI->getVideoFramerateAsString();
	hh->ParamList["AudioType"] = NeutrinoAPI->getAudioInfoAsString();
	hh->ParamList["Crypt"] = NeutrinoAPI->getCryptInfoAsString();
	return "";
}
Пример #11
0
/* write a value in hexadecimal, either as a full cell or a half cell, and
 * optionally add a newline
 */
SC_FUNC void outval(cell val,int fullcell,int newline)
{
  char *str=itoh(val);
  #if !defined AMX_NO_PACKED_OPC
    if (!fullcell) {
      assert(strlen(str)==2*sizeof(cell));
      assert((str[0]=='0' || str[0]=='f') && (str[1]=='0' || str[1]=='f'));
      #if PAWN_CELL_SIZE>=32
        assert((str[2]=='0' || str[2]=='f') && (str[3]=='0' || str[3]=='f'));
      #endif
      #if PAWN_CELL_SIZE>=64
        assert((str[4]=='0' || str[4]=='f') && (str[5]=='0' || str[5]=='f'));
        assert((str[6]=='0' || str[6]=='f') && (str[7]=='0' || str[7]=='f'));
      #endif
      str+=sizeof(cell);
    } /* if */
  #else
    (void)fullcell;
  #endif
  stgwrite(str);
  if (newline)
    stgwrite("\n");
}
Пример #12
0
Файл: sc4.c Проект: Oukache/pawn
/* write a value in hexadecimal, either as a full cell or a half cell, and
 * optionally add a newline
 */
SC_FUNC void outval(cell val,int fullcell,int newline)
{
  char *str=itoh(val);
  #if !defined AMX_NO_PACKED_OPC
    if (!fullcell) {
      #if !defined NDEBUG
        assert(strlen(str)==2*(size_t)pc_cellsize);
        assert((str[0]=='0' || str[0]=='f') && (str[1]=='0' || str[1]=='f'));
        if (pc_cellsize>=4)
          assert((str[2]=='0' || str[2]=='f') && (str[3]=='0' || str[3]=='f'));
        if (pc_cellsize>=8) {
          assert((str[4]=='0' || str[4]=='f') && (str[5]=='0' || str[5]=='f'));
          assert((str[6]=='0' || str[6]=='f') && (str[7]=='0' || str[7]=='f'));
        } /* if */
      #endif
      str+=pc_cellsize;
    } /* if */
  #else
    (void)fullcell;
  #endif
  stgwrite(str);
  if (newline)
    stgwrite("\n");
}
Пример #13
0
static int matchsequence(char *start,char *end,char *pattern,
                         char symbols[MAX_OPT_VARS][MAX_ALIAS+1],
                         int *match_length)
{
  int var,i;
  char str[MAX_ALIAS+1];
  char *start_org=start;
  cell value;
  char *ptr;

  *match_length=0;
  for (var=0; var<MAX_OPT_VARS; var++)
    symbols[var][0]='\0';

  while (*start=='\t' || *start==' ')
    start++;
  while (*pattern) {
    if (start>=end)
      return FALSE;
    switch (*pattern) {
    case '%':   /* new "symbol" */
      pattern++;
      assert(isdigit(*pattern));
      var=atoi(pattern) - 1;
      assert(var>=0 && var<MAX_OPT_VARS);
      assert(*start=='-' || alphanum(*start));
      for (i=0; start<end && (*start=='-' || *start=='+' || alphanum(*start)); i++,start++) {
        assert(i<=MAX_ALIAS);
        str[i]=*start;
      } /* for */
      str[i]='\0';
      if (symbols[var][0]!='\0') {
        if (strcmp(symbols[var],str)!=0)
          return FALSE; /* symbols should be identical */
      } else {
        strcpy(symbols[var],str);
      } /* if */
      break;
    case '-':
      value=-strtol(pattern+1,&pattern,16);
      ptr=itoh((ucell)value);
      while (*ptr!='\0') {
        if (tolower(*start) != tolower(*ptr))
          return FALSE;
        start++;
        ptr++;
      } /* while */
      pattern--;  /* there is an increment following at the end of the loop */
      break;
    case ' ':
      if (*start!='\t' && *start!=' ')
        return FALSE;
      while ((start<end && *start=='\t') || *start==' ')
        start++;
      break;
    case '!':
      while ((start<end && *start=='\t') || *start==' ')
        start++;                /* skip trailing white space */
      if (*start!='\n')
        return FALSE;
      assert(*(start+1)=='\0');
      start+=2;                 /* skip '\n' and '\0' */
      if (*(pattern+1)!='\0')
        while ((start<end && *start=='\t') || *start==' ')
          start++;              /* skip leading white space of next instruction */
      break;
    default:
      if (tolower(*start) != tolower(*pattern))
        return FALSE;
      start++;
    } /* switch */
    pattern++;
  } /* while */

  *match_length=(int)(start-start_org);
  return TRUE;
}
Пример #14
0
Файл: sc4.c Проект: jte/pawn
/* write a value in hexadecimal; optionally adds a newline */
SC_FUNC void outval(cell val,int newline)
{
  stgwrite(itoh(val));
  if (newline)
    stgwrite("\n");
}
Пример #15
0
Файл: sc4.c Проект: jte/pawn
/* When a subroutine returns to address 0, the AMX must halt. In earlier
 * releases, the RET and RETN opcodes checked for the special case 0 address.
 * Today, the compiler simply generates a HALT instruction at address 0. So
 * a subroutine can savely return to 0, and then encounter a HALT.
 */
SC_FUNC void writeleader(symbol *root)
{
  int lbl_nostate,lbl_table;
  int statecount;
  symbol *sym;
  constvalue *fsa, *state, *stlist;
  int fsa_id,listid;
  char lbl_default[sNAMEMAX+1];

  assert(code_idx==0);

  begcseg();
  stgwrite(";program exit point\n");
  stgwrite("\thalt 0\n\n");
  code_idx+=opcodes(1)+opargs(1);       /* calculate code length */

  /* check whether there are any functions that have states */
  for (sym=root->next; sym!=NULL; sym=sym->next)
    if (sym->ident==iFUNCTN && (sym->usage & (uPUBLIC | uREAD))!=0 && sym->states!=NULL)
      break;
  if (sym==NULL)
    return;             /* no function has states, nothing to do next */

  /* generate an error function that is called for an undefined state */
  stgwrite("\n;exit point for functions called from the wrong state\n");
  lbl_nostate=getlabel();
  setlabel(lbl_nostate);
  stgwrite("\thalt ");
  outval(AMX_ERR_INVSTATE,TRUE);
  code_idx+=opcodes(1)+opargs(1);       /* calculate code length */

  /* write the "state-selectors" table with all automatons (update the
   * automatons structure too, as we are now assigning the address to
   * each automaton state-selector variable)
   */
  assert(glb_declared==0);
  begdseg();
  for (fsa=sc_automaton_tab.next; fsa!=NULL; fsa=fsa->next) {
    defstorage();
    stgwrite("0\t; automaton ");
    if (strlen(fsa->name)==0)
      stgwrite("(anonymous)");
    else
      stgwrite(fsa->name);
    stgwrite("\n");
    fsa->value=glb_declared*sizeof(cell);
    glb_declared++;
  } /* for */

  /* write stubs and jump tables for all state functions */
  begcseg();
  for (sym=root->next; sym!=NULL; sym=sym->next) {
    if (sym->ident==iFUNCTN && (sym->usage & (uPUBLIC | uREAD))!=0 && sym->states!=NULL) {
      stlist=sym->states->next;
      assert(stlist!=NULL);     /* there should be at least one state item */
      listid=stlist->index;
      assert(listid==-1 || listid>0);
      if (listid==-1 && stlist->next!=NULL) {
        /* first index is the "fallback", take the next one (if available) */
        stlist=stlist->next;
        listid=stlist->index;
      } /* if */
      if (listid==-1) {
        /* first index is the fallback, there is no second... */
        strcpy(stlist->name,"0"); /* insert dummy label number */
        /* this is an error, but we postpone adding the error message until the
         * function definition
         */
        continue;
      } /* if */
      /* generate label numbers for all statelist ids */
      for (stlist=sym->states->next; stlist!=NULL; stlist=stlist->next) {
        assert(strlen(stlist->name)==0);
        strcpy(stlist->name,itoh(getlabel()));
      } /* for */
      if (strcmp(sym->name,uENTRYFUNC)==0)
        continue;               /* do not generate stubs for this special function */
      sym->addr=code_idx;       /* fix the function address now */
      /* get automaton id for this function */
      assert(listid>0);
      fsa_id=state_getfsa(listid);
      assert(fsa_id>=0);        /* automaton 0 exists */
      fsa=automaton_findid(fsa_id);
      /* count the number of states actually used; at the sane time, check
       * whether there is a default state function
       */
      statecount=0;
      strcpy(lbl_default,itoh(lbl_nostate));
      for (stlist=sym->states->next; stlist!=NULL; stlist=stlist->next) {
        if (stlist->index==-1) {
          assert(strlen(stlist->name)<sizeof lbl_default);
          strcpy(lbl_default,stlist->name);
        } else {
          statecount+=state_count(stlist->index);
        } /* if */
      } /* for */
      /* generate a stub entry for the functions */
      stgwrite("\tload.pri ");
      outval(fsa->value,FALSE);
      stgwrite("\t; ");
      stgwrite(sym->name);
      stgwrite("\n");
      code_idx+=opcodes(1)+opargs(1);   /* calculate code length */
      lbl_table=getlabel();
      ffswitch(lbl_table);
      /* generate the jump table */
      setlabel(lbl_table);
      ffcase(statecount,lbl_default,TRUE);
      for (state=sc_state_tab.next; state!=NULL; state=state->next) {
        if (state->index==fsa_id) {
          /* find the label for this list id */
          for (stlist=sym->states->next; stlist!=NULL; stlist=stlist->next) {
            if (stlist->index!=-1 && state_inlist(stlist->index,(int)state->value)) {
              ffcase(state->value,stlist->name,FALSE);
              break;
            } /* if */
          } /* for */
          if (stlist==NULL && strtol(lbl_default,NULL,16)==lbl_nostate)
            error(230,state->name,sym->name);  /* unimplemented state, no fallback */
        } /* if (state belongs to automaton of function) */
      } /* for (state) */
      stgwrite("\n");
    } /* if (is function, used & having states) */
  } /* for (sym) */
}
Пример #16
0
static int matchsequence(char *start,char *end,const char *pattern,
                         char symbols[MAX_OPT_VARS+1][MAX_ALIAS+1],
                         int *match_length)
{
  int var,i,optsym;
  char str[MAX_ALIAS+1];
  char *start_org=start;
  cell value;
  char *ptr;

  *match_length=0;
  optsym=FALSE;
  for (var=0; var<=MAX_OPT_VARS; var++)
    symbols[var][0]='\0';

  while (*start=='\t' || *start==' ')
    start++;
  while (*pattern) {
    if (start>=end)
      return FALSE;
    switch (*pattern) {
    case '%':   /* new "symbol" */
      pattern++;
      assert(isdigit(*pattern));
      var=atoi(pattern);
      assert(var>=0 && var<=MAX_OPT_VARS);
      assert(*start=='-' || alphanum(*start) || optsym);
      for (i=0; start<end && (*start=='-' || *start=='+' || alphanum(*start)); i++,start++) {
        assert(i<=MAX_ALIAS);
        str[i]=*start;
      } /* for */
      str[i]='\0';
      if (var==0) {
        /* match only if the parameter is numeric and in the range of a half cell */
        const char *ptr;
        /* getparamvalue() resolves leading '-' on values and adds multiple
         * values (the peephole optimizer may create such variants)
         */
        ucell v=getparamvalue(str,&ptr);
        if (*ptr>' ' || v>=((ucell)1<<((pc_cellsize*4)-1)) && v<=~((ucell)1<<((pc_cellsize*4)-1)))
          return FALSE;
        /* reconvert the value to a string (without signs or expressions) */
        ptr=itoh(v);
        #if !defined NDEBUG
          assert(strlen(ptr)==2*pc_cellsize);
          assert((ptr[0]=='0' || ptr[0]=='f') && (ptr[1]=='0' || ptr[1]=='f'));
          if (pc_cellsize>=32)
            assert((ptr[2]=='0' || ptr[2]=='f') && (ptr[3]=='0' || ptr[3]=='f'));
          if (pc_cellsize>=64) {
            assert((ptr[4]=='0' || ptr[4]=='f') && (ptr[5]=='0' || ptr[5]=='f'));
            assert((ptr[6]=='0' || ptr[6]=='f') && (ptr[7]=='0' || ptr[7]=='f'));
          } /* if */
        #endif
        if (v==0) {
          str[0]='0'; /* make zero transform to '0' rather than '0000' */
          str[1]='\0';
        } else {
          memmove(str,ptr+pc_cellsize,pc_cellsize+1);
        } /* if */
      } /* if */
      if (symbols[var][0]!='\0') {
        if (strcmp(symbols[var],str)!=0)
          return FALSE; /* symbols should be identical */
      } else {
        strcpy(symbols[var],str);
      } /* if */
      optsym=FALSE;
      break;
    case '-':
      value=-hex2cell(pattern+1,&pattern);
      ptr=itoh((ucell)value);
      while (*ptr!='\0') {
        if (tolower(*start) != tolower(*ptr))
          return FALSE;
        start++;
        ptr++;
      } /* while */
      pattern--;  /* there is an increment following at the end of the loop */
      break;
    case '+':
      value=hex2cell(pattern+1,&pattern);
      ptr=itoh((ucell)value);
      while (*ptr!='\0') {
        if (tolower(*start) != tolower(*ptr))
          return FALSE;
        start++;
        ptr++;
      } /* while */
      pattern--;  /* there is an increment following at the end of the loop */
      break;
    case ' ':     /* required whitespace */
      if (*start!='\t' && *start!=' ')
        return FALSE;
      while (start<end && (*start=='\t' || *start==' '))
        start++;
      break;
    case '~':     /* optional whitespace (followed by optional symbol) */
      while (start<end && (*start=='\t' || *start==' '))
        start++;
      optsym= (pattern[1]=='%');
      break;
    case '!':
      while (start<end && (*start=='\t' || *start==' '))
        start++;                /* skip trailing white space */
      if (*start==';')
        while (start<end && *start!='\n')
          start++;              /* skip trailing comment */
      if (*start!='\n')
        return FALSE;
      assert(*(start+1)=='\0');
      start+=2;                 /* skip '\n' and '\0' */
      if (*(pattern+1)!='\0')
        while (start<end && *start=='\t' || *start==' ')
          start++;              /* skip leading white space of next instruction */
      break;
    default:
      if (tolower(*start) != tolower(*pattern))
        return FALSE;
      start++;
    } /* switch */
    pattern++;
  } /* while */

  *match_length=(int)(start-start_org);
  return TRUE;
}
Пример #17
0
static char *replacesequence(const char *pattern,char symbols[MAX_OPT_VARS+1][MAX_ALIAS+1],int *repl_length)
{
  char *lptr;
  int var,optsym;
  char *buffer;

  /* calculate the length of the new buffer
   * this is the length of the pattern plus the length of all symbols (note
   * that the same symbol may occur multiple times in the pattern) plus
   * line endings and startings ('\t' to start a line and '\n\0' to end one)
   */
  assert(repl_length!=NULL);
  *repl_length=0;
  optsym=FALSE;
  lptr=(char*)pattern;
  while (*lptr) {
    switch (*lptr) {
    case '%':
      lptr++;           /* skip '%' */
      assert(isdigit(*lptr));
      var=atoi(lptr);
      assert(var>=0 && var<=MAX_OPT_VARS);
      assert(symbols[var][0]!='\0' || optsym);  /* variable should be defined */
      assert(var!=0 || strlen(symbols[var])==pc_cellsize || (symbols[var][0]=='-' && strlen(symbols[var])==pc_cellsize+1) || atoi(symbols[var])==0);
      *repl_length+=(int)strlen(symbols[var]);
      optsym=FALSE;
      break;
    case '~': /* optional space followed by optional symbol */
      assert(lptr[1]=='%');
      assert(isdigit(lptr[2]));
      var=atoi(lptr+2);
      assert(var>=0 && var<=MAX_OPT_VARS);
      if (symbols[var][0]!='\0')
        *repl_length+=1;  /* copy space if following symbol is valid */
      else
        optsym=TRUE;      /* don't copy space, and symbol is optional */
      break;
    case '#':
      lptr++;           /* skip '#' */
      assert(alphanum(*lptr));
      while (alphanum(lptr[1]))
        lptr++;
      *repl_length+=pc_cellsize*2;
      break;
    case '!':
      *repl_length+=3;  /* '\t', '\n' & '\0' */
      break;
    default:
      *repl_length+=1;
    } /* switch */
    lptr++;
  } /* while */

  /* allocate a buffer to replace the sequence in */
  if ((buffer=(char*)malloc(*repl_length))==NULL) {
	error(103);
    return NULL;
  } /* if */

  /* replace the pattern into this temporary buffer */
  optsym=FALSE;
  lptr=buffer;
  *lptr++='\t';         /* the "replace" patterns do not have tabs */
  while (*pattern) {
    assert((int)(lptr-buffer)<*repl_length);
    switch (*pattern) {
    case '%':
      /* write out the symbol */
      pattern++;
      assert(isdigit(*pattern));
      var=atoi(pattern);
      assert(var>=0 && var<=MAX_OPT_VARS);
      assert(symbols[var][0]!='\0' || optsym);  /* variable should be defined */
      assert(symbols[var][0]=='\0' || !optsym); /* but optional variable should be undefined */
      strcpy(lptr,symbols[var]);
      lptr+=strlen(symbols[var]);
      optsym=FALSE;
      break;
    case '~':
      assert(pattern[1]=='%');
      assert(isdigit(pattern[2]));
      var=atoi(pattern+2);
      assert(var>=0 && var<=MAX_OPT_VARS);
      if (symbols[var][0]!='\0')
        *lptr++=' ';      /* replace ~ by a space */
      else
        optsym=TRUE;      /* don't copy space, and symbol is optional */
      break;
    case '#': {
      ucell v=hex2ucell(pattern+1,NULL);
      char *ptr=itoh(v);
      strcpy(lptr,ptr);
      lptr+=strlen(ptr);
      assert(alphanum(pattern[1]));
      while (alphanum(pattern[1]))
        pattern++;
      break;
    } /* case */
    case '!':
      /* finish the line, optionally start the next line with an indent */
      *lptr++='\n';
      *lptr++='\0';
      if (*(pattern+1)!='\0')
        *lptr++='\t';
      break;
    default:
      *lptr++=*pattern;
    } /* switch */
    pattern++;
  } /* while */

  assert((int)(lptr-buffer)==*repl_length);
  return buffer;
}
Пример #18
0
void sh_itoh(char* params){
	char s[3];
	s[2] = 0;
	itoh(strToInt(params),s);
	ttprintln(s);
}