Exemple #1
0
static int
parse_struct_version (const char *start, const char *end, CK_VERSION_PTR version)
{
	const char *dot;
	int val;

	assert (start <= end);

	dot = memchr (start, '.', end - start);
	if (!dot)
		dot = end;

	if (dot == start)
		return P11_KIT_URI_BAD_VERSION;
	val = atoin (start, dot);
	if (val < 0 || val >= 255)
		return P11_KIT_URI_BAD_VERSION;
	version->major = (CK_BYTE)val;
	version->minor = 0;

	if (dot != end) {
		if (dot + 1 == end)
			return P11_KIT_URI_BAD_VERSION;
		val = atoin (dot + 1, end);
		if (val < 0 || val >= 255)
			return P11_KIT_URI_BAD_VERSION;
		version->minor = (CK_BYTE)val;
	}

	return 1;
}
Exemple #2
0
void __fastcall CCradio::SendCommand(LPCSTR p)
{
	int	c;
	int f;

	for(f = 0; *p; p++){
		if( *p == '\\' ){
			f = 0;
			p++;
			switch(*p){
				case '$':
					f = 1;
					continue;
				case 'x':
				case 'X':
					p++;
					if( *p == 'x' ){
						c = RADIO.Cmdxx;
					}
					else {
						c = htoin(p, 2);
					}
					p++;
					break;
				case 'r':
					c = CR;
					break;
				case 'n':
					c = LF;
					break;
				case 'w':
					p++;
					c = atoin(p, 2);
					if( (c < 0) || (c >= 100) ) c = 100;
					if( c ) ::Sleep(c * 10);
					p++;
					continue;
				case '\\':
					c = '\\';
					break;
				case 'c':	// comment
					return;
			}
		}
		else if( f ){
			p = SkipSpace(p);
			if( *p == 'x' ){
				c = RADIO.Cmdxx;
			}
			else {
				c = htoin(p, 2);
			}
			p++;
		}
		else {
			c = *p;
		}
		PutChar(BYTE(c));
	}
}
Exemple #3
0
void go() {
    int result;
    int tr;
    int trtid;
    char buf[4];
    char ch;
    track_edge *edge;
    unsigned int dist;
    track_node track[TRACK_MAX];

    init_track(track);
    printf("Enter Train Number: ");
    gets(IO, buf, 4);
    tr = atoin(buf, &result);

    trtid = TrCreate(6, tr, &track[24].edge[DIR_AHEAD]);
    TrSpeed(trtid, 0);

    while (true) {
        ch = getchar();
        switch (ch) {
        case 's':
            TrSpeed(trtid, 8);
            break;
        case 't':
            TrSpeed(trtid, 0);
            break;
        case 'r':
            TrReverse(trtid);
            break;
        case 'g':
            TrGetLocation(trtid, &edge, &dist);
            printf("train %d at %d after sensor %s\n", trtid, dist, edge->src->name);
            break;
        case 'q':
            turnOffTrainSet();
            Delay(10);
            SigTerm(0);
            Exit();
            break;
        default:
            break;
        }
    }
}
Exemple #4
0
inline void CStringEx::ftoan(char *alpha,float val,int len)
{
 char format[16];
 int exp,i;
 unsigned int lenx;
 char *temp;
 /* do we need to use exponential */
 if(val < 0.0) sprintf(format,"%7.2E",val);
 else          sprintf(format,"%8.2E",val);
 exp=strlen(&format[6]);
 exp=atoin(&format[6],exp);
 if( (val>=0 && exp+3 >len) || (val<0 && exp+4 >len) || (exp>2 && fabs(val)<1.0))
 { /* use E format */
   lenx=len+7;
   i=sizeof(char);
   temp=(char near *)calloc(lenx,i);
   if(val < 0.0) sprintf(format,"%c%d.%dE",'%',len-1,len-5);
   else          sprintf(format,"%c%d.%dE",'%',len,len-4);
   sprintf(temp,format,val);
   lenx=strlen(temp);
   i=lenx-2;
   do {
      if(temp[i]=='0') strcpy(&temp[i],&temp[i+1]);
      else i--;
      } while(i>0 && temp[i]!='E');
	if(temp[i]=='E' && temp[i+1]=='+') strcpy(&temp[i+1],&temp[i+2]);
	while (len < (int) strlen(temp))
      {
      i--;
      strcpy(&temp[i],&temp[i+1]);
      }
   strcpy(alpha,temp);
   free(temp);
 }
 else
 { /* use f format */
   if(val < -1.0) sprintf(format,"%c%d.%df",'%',len-1,len-3-exp);
   else if (val< 0.) sprintf(format,"%c%d.%df",'%',len-1,len-3);
   else if (val< 1.) sprintf(format,"%c%d.%df",'%',len,len-2);
   else          sprintf(format,"%c%d.%df",'%',len,len-2-exp);
   sprintf(alpha,format,val);
 }
 return;
}
Exemple #5
0
char *marc_read(FILE *inf)
{
    char length_str[5];
    size_t size;
    char *buf;

    if (fread (length_str, 1, 5, inf) != 5)
        return NULL;
    size = atoin (length_str, 5);
    if (size <= 6)
        return NULL;
    if (!(buf = xmalloc (size+1)))
        return NULL;
    if (fread (buf+5, 1, size-5, inf) != (size-5))
    {
        xfree (buf);
        return NULL;
    }
    memcpy (buf, length_str, 5);
    buf[size] = '\0';
    return buf;
}
Exemple #6
0
//readprint -i inputfile -o outputfile
//readprint < inputfile > outputfile
int main(int argc, char *argv[]){
	FILE *inputfp=stdin;
	FILE *outputfp=stdout;
	char *files[2]={0,0};
	if(argc > 5){
		fprintf(stderr,"line 12 readprint -i inputfile -o outputfile\n");
		exit(0);
	}
	int i=1;
	while(i < argc){
		if( strcmp(argv[i],"-i") == 0){
			files[0]=argv[i+1];
			i+=2;
		}	
		else if(strcmp(argv[i],"-o")==0){
			files[1]=argv[i+1];
			i+=2;
		}
		else{
			fprintf(stderr,"line 26 readprint -i inputfile -o outputfile\n");
		 exit(0);
		}		
	}	
 if(files[0])fprintf(stderr,"reading in from %s\n",files[0]);
 else fprintf(stderr,"reading from stdin\n");
 if(files[1])fprintf(stderr,"writing to %s\n",files[1]);
 else fprintf(stderr,"writing to stdout\n");
 
 char buffer[4];
 char *line = malloc(sizeof(buffer)+1);
 int lineSize = sizeof(buffer)+1;
 line[0] = '\0';
 while(fgets(buffer,sizeof(buffer),inputfp)){
 	while(strlen(buffer) + strlen(line) +1 < LineSize) {
 		line = realloc(line,lineSize*2);
 		lineSize = lineSize*2;
 	}
 	strcat(line,buffer);
 	if (buffer[strlen(buffer)-1] == '\n' || strlne(buffer) < sizeof(buffer)-1) {
 		fprint(outputfp, "%s\n", line);
 		 line[0] = '\0';
 	}
 	
 }
 if(line)free(line);



 char line[4096];
 if(files[0]){
		inputfp=fopen(files[0],"r");
		if(!inputfp)exit(0);
}
if(files[1]){
	outputfp=fopen(files[1],"w");
	if(!outputfp)exit(0);
}
char *pch;
char delim[] = " \n";
pch = strotok(line, delim);
// kirk captain   1234\n
 int nRecords = 0;
 while(pch) {
 	if(nRecords %3 == 2) {
 		fprintf(outputfp,"serial number is %d\n",atoin(pch));
 	}
 	pch = strtok(0, delim);
 	nRecords++;
 }
 }
Exemple #7
0
int CStringEx::GetInt()
{
	return atoin(GetBuffer(GetLength()),GetLength());
}
Exemple #8
0
int sscanformatted(const char *input, const char *fmt, va_list va) {
    char ch;
    int conv;
    char *tmp;
    unsigned int i;
    unsigned int base;
    unsigned int conversion_type;
    unsigned int nread;
    unsigned int nassigned;
    unsigned int len = strlen(input);
    char buffer[len];
    char *buf = buffer;

    nread = 0;
    nassigned = 0;

    while (true) {
        if (!(ch = *fmt++)) {
            break;
        } else if (len <= 0) {
            return -1;
        } else if (isspace(ch)) {
            while (*fmt && isspace(*fmt)) {
                *fmt++;
            }
            continue;
        }

        if (ch != '%') {
            if (*input != ch || len <= 0) {
                return -1;
            }
            input++;
            nread++;
            len--;
            continue;
        }

        nread++;
        ch = *fmt++;

        switch (ch) {
            case 'd':
                conversion_type = __INT;
                base = 10;
                break;
            case 'X':
            case 'x':
            case 'p':
                conversion_type = __HEX;
                base = 16;
                break;
            case 's':
                conversion_type = __STR;
                break;
            case 'i':
                conversion_type = __INT;
                base = 10;
                break;
            case 'u':
                conversion_type = __UINT;
                base = 10;
                break;
            case 'c':
                conversion_type = __CHAR;
                break;
            case 'l':
                conversion_type = __LONG;
                break;
            default:
                return -1;
        }

        while (isspace(*input)) {
            ++input;
            --len;
        }

        if (*input == 0) {
            return -1;
        } else if (conversion_type == __CHAR) {
            buf[0] = *input++;
            buf[1] = 0;
            --len;
        } else {
            for (i = 0; !isspace(*input) && ((buf[i] = *input++)); ++i) {
                --len;
            }
            buf[i] = 0;
        }

        switch (conversion_type) {
            case __INT:
                *va_arg(va, int*) = atoin(buf, &conv);
                if (conv == 0) return -1;
                break;
            case __CHAR:
                *va_arg(va, char*) = buf[0];
                break;
            case __UINT:
                *va_arg(va, unsigned int*) = (unsigned int)atoin(buf, &conv);
                if (conv == 0) return -1;
                break;
            case __HEX:
                *va_arg(va, unsigned int*) = (unsigned int)atoi(buf, &conv);
                if (conv == 0) return -1;
                break;
            case __STR:
                tmp = va_arg(va, char*);
                while ((*tmp++ = *buf++));
                break;
        }
        nassigned++;
    }

    while (*input && isspace(*input)) {
        input++;
        --len;
    }

    if (len != 0) {
        return -1;
    }
    return nassigned;
}