Exemplo n.º 1
0
static int
output(int a, int b)
{
	int i;
	char *s;

	if (a < 0)
		change(n0-1, 0, n1, b, "a");
	else if (b < 0)
		change(n0, a, n1-1, 0, "d");
	else
		change(n0, a, n1, b, "c");
	for (i = 0; i <= a; i++) {
		s = getl(0, n0+i);
		if (s == NULL)
			break;
		(void) printf("< %s", s);
		clrl(0, n0+i);
	}
	n0 += i-1;
	if (a >= 0 && b >= 0)
		(void) printf("---\n");
	for (i = 0; i <= b; i++) {
		s = getl(1, n1+i);
		if (s == NULL)
			break;
		(void) printf("> %s", s);
		clrl(1, n1+i);
	}
	diffFound = 1;
	n1 += i-1;
	return (1);
}
Exemplo n.º 2
0
int
main(int argc, char **argv)
{
	char *s0, *s1;

	if ((argc > 1) && (*argv[1] == '-')) {
		argc--;
		argv++;
		while (*++argv[0])
			if (*argv[0] == 'b')
				bflag++;
	}

	(void) setlocale(LC_ALL, "");
#if !defined(TEXT_DOMAIN)		/* Should be defined by cc -D */
#define	TEXT_DOMAIN	"SYS_TEST"	/* Use this only if it weren't */
#endif
	(void) textdomain(TEXT_DOMAIN);

	if (argc != 3)
		error(gettext("must have 2 file arguments"));
	file[0] = dopen(argv[1], argv[2]);
	file[1] = dopen(argv[2], argv[1]);
	for (;;) {
		s0 = getl(0, ++n0);
		s1 = getl(1, ++n1);
		if (s0 == NULL || s1 == NULL)
			break;
		if (cmp(s0, s1) != 0) {
			if (!easysynch() && !hardsynch())
				progerr("5");
		} else {
			clrl(0, n0);
			clrl(1, n1);
		}
	}
	/* diff is expected to return 1 if the files differ */
	if (s0 == NULL && s1 == NULL)
		return (diffFound);
	if (s0 == NULL) {
		(void) output(-1, INF);
		return (1);
	}
	if (s1 == NULL) {
		(void) output(INF, -1);
		return (1);
	}
	/* NOTREACHED */
	return (0);
}
Exemplo n.º 3
0
main() 
{

    int i,len,max;
//    MAX=10;
    char line[1000],maxline[1000];
    
    i=len=max=0;
    
    
    for (i=0;i<MAX;++i)
	line[i]=maxline[i]=0;

    for (i=0;i<MAX;++i)
	printf("line[%d]=%d; maxline[%d]=%d;\n",i,line[i],i,maxline[i]);

    while((len=getl(line) )>0){
	if (len>max){
	    max=len;
	    copy_line(len,line,maxline);
	}
    }
    
    printf("longest string =%s;\n",maxline);

}
Exemplo n.º 4
0
Arquivo: much.c Projeto: gabc/much
static void
dobacksearch()
{
	char *str;
	regex_t reg;
	int st, i;

	(void) printw("?");
	(void) refresh();
	str = getl();

	if(strlen(str) == 0)
		str = strncpy(str, lastreg, 80);

	st = regcomp(&reg, str, 0);
	if(st != 0){
		(void) printw("Bad regex");
		(void) refresh();
		free(str);
		return;
	}

	lastreg = strncpy(lastreg, str, 80);

	for(i = v_end -2; i > start; i--){
		st = regexec(&reg, buffer[i], 0, NULL, 0);
		if(st == 0){
			v_start = i - LINES;
			v_end = i;
			repaint();
			break;
		}
	}
	free(str);
}
Exemplo n.º 5
0
int main()
{
    int i,c,len,k;
    char symb1,symb2,symb3;
    char line[MAX];

    for (i=0;i<MAX;++i){
	line[i]=0;
    }

    len=0;
    symb1='\t';
    symb2=' ';
    symb3='\n';
    while( (len=getl(line,MAX) )>0 ){
	printf("string line before detabing=\n%s;\nlen before detabing =%d\n",line,len);

	for (k=0;k<len;++k)
	    printf("entabed[%d]='%c',entabed[%d+%d-1]='%c',k=%d,\n",k,line[k],k,TAB,line[k-TAB],k);

	len=entab(line,len);

	printf("string line  after detabing=\n%s;len after detabing=%d\n",line,len);

	for (k=0;k<len;++k)
	    printf("entabed[%d]='%c',entabed[%d+%d-1]='%c',k=%d,\n",k,line[k],k,TAB,line[k-TAB],k);
    	
    }
    
    for (i=0;i<=len;++i)	
	printf("entabed[%d]=%c",i,line[i]);

}
Exemplo n.º 6
0
main() 
{

    int i,len,maxlen;
//    MAX=10;
    char line[MAX],maxline[MAX];
    
    i=len=maxlen=0;
    
    
    for (i=0;i<MAX;++i)
	line[i]=maxline[i]=0;

    for (i=0;i<MAX;++i)
	printf("line[%d]=%d; maxline[%d]=%d;\n",i,line[i],i,maxline[i]);

    while((len=getl(line,maxline,MAX))>0){
	if (len>maxlen){
	    maxlen=len;
	    copy_line(len,line,maxline);
	}
	    printf("string line=%s;maxline=%s\n",line,maxline);
    }
    if (maxlen>0)
	printf("longest string =%s;\n",maxline);

}
Exemplo n.º 7
0
void
init_term(char *filename, char **termname)
{
  FILE *fd;
  int n;
  static char buf[512];
  char *p;
  
  fprintf(stderr, "Reading in term file (optional)...");
  
  if ((fd = fopen_readfile(filename)) == NULL) {
    termname[0] = NULL;
    fprintf(stderr, "not found\n");
    return;
  }

  while (getl(buf, sizeof(buf), fd) != NULL) {
    if ((p = strtok(buf, DELM)) == NULL) {
      fprintf(stderr, "Error: term file failed to parse, corrupted or invalid data?\n");
      return;
    }
    n = atoi(p);
    if ((p = strtok(NULL, DELM)) == NULL) {
      fprintf(stderr, "Error: term file failed to parse, corrupted or invalid data?\n");
      return;
    }
    termname[n] = strdup(p);
  }
  if (fclose_readfile(fd) == -1) {
    fprintf(stderr, "close error\n");
    exit(1);
  }

  fprintf(stderr, "done\n");
}
Exemplo n.º 8
0
WObject* WEXPORT WObjectFile::readObject()
{
    int index = (int)getl();
    readEOItem();
    if( index < 0 ) {
        //no object data to read
        return( NULL );
    } else if( index < _objects.count() ) {
        return( _objects[index] );
    } else {
        WString name;
        gets( name );
        readEOItem();
        _objects.add( NULL );   //'create' may add some more!
        WObject* obj = WClass::createObject( name, *this );
        if( obj == NULL ) {
            //internal error: should never happen!
            _objOk = false;
        } else {
            _objects.replaceAt( index, obj );
            obj->readSelf( *this );
        }
        return( obj );
    }
}
Exemplo n.º 9
0
int
Bgetheader(Biobuf *b, Header *h)
{
	Icon *icon;
	int i;
	uint8_t buf[40];

	memset(h, 0, sizeof(*h));
	if(Bread(b, buf, 6) != 6)
		goto eof;
	if(gets(&buf[0]) != 0)
		goto header;
	if(gets(&buf[2]) != 1)
		goto header;
	h->n = gets(&buf[4]);

	for(i = 0; i < h->n; i++){
		icon = mallocz(sizeof(*icon), 1);
		if(icon == nil)
			sysfatal("malloc: %r");
		if(Bread(b, buf, 16) != 16)
			goto eof;
		icon->w = buf[0];
		icon->h = buf[1];
		icon->ncolor = buf[2] == 0 ? 256 : buf[2];
		if(buf[3] != 0)
			goto header;
		icon->nplane = gets(&buf[4]);
		icon->bits = gets(&buf[6]);
		icon->len = getl(&buf[8]);
		icon->offset = getl(&buf[12]);

		if(i == 0)
			h->first = icon;
		else
			h->last->next = icon;
		h->last = icon;
	}
	return 0;

eof:
	werrstr("unexpected EOF");
	return -1;
header:
	werrstr("unknown header format");
	return -1;
}
Exemplo n.º 10
0
/**
 * read_phy_reg - MII interface  to read  @reg_addr register of phy at @phy_addr
 * return positive and zero value if success, or negative value if fail
 * may be used by other standard ethernet phy
 */
unsigned short read_phy_reg_ksz8041(ec_priv_t * ecp, unsigned short reg_addr)
{
	u32 op_reg;

	do {
		op_reg = getl(MAC_CSR10);
	} while (op_reg & MII_MNG_SB);

	putl(MII_MNG_SB | MII_MNG_OPCODE(MII_OP_READ) | MII_MNG_REGADD(reg_addr) |
		MII_MNG_PHYADD(ASOC_ETHERNET_PHY_ADDR), MAC_CSR10);

	do {
		op_reg = getl(MAC_CSR10);
	} while (op_reg & MII_MNG_SB);

	return (u16)MII_MNG_DATA(op_reg);
}
Exemplo n.º 11
0
/**
 * write_phy_reg - MII interface  to write  @val to @reg_addr register of phy at @phy_addr
 * return zero if success, negative value if fail
 * may be used by other standard ethernet phy
 */
int write_phy_reg_ksz8041(ec_priv_t * ecp, unsigned short reg_addr, unsigned short val)
{
	u32 op_reg;

	do {
		op_reg = getl(MAC_CSR10);
	} while (op_reg & MII_MNG_SB);

	putl(MII_MNG_SB | MII_MNG_OPCODE(MII_OP_WRITE) | MII_MNG_REGADD(reg_addr) |
		MII_MNG_PHYADD(ASOC_ETHERNET_PHY_ADDR) | val, MAC_CSR10);

	do {
		op_reg = getl(MAC_CSR10);
	} while (op_reg & MII_MNG_SB);

	return 0;
}
Exemplo n.º 12
0
Graph* createGraph(FILE* fid) {
  char buffer[LINELEN+1]; // Line buffer for reading
  bool undirected;  // true if graph is undirected, false if directed
  int i;
  int v1, v2, dist;

  if (getl(buffer, LINELEN, fid) == NULL) // Unable to get number of vertices
{ cout << "Unable to read number of vertices\n";
    return NULL;
}

  Graph* G = new GType(atoi(buffer));

  if (getl(buffer, LINELEN, fid) == NULL) // Unable to get graph type
{ cout << "Unable to read graph type\n";
    return NULL ;
}
  if (buffer[0] == 'U')
    undirected = true;
  else if (buffer[0] == 'D')
    undirected = false;
  else {
    cout << "Bad graph type: |" << buffer << "|\n";
    return NULL;
  }

  // Read in edges
  while (getl(buffer, LINELEN, fid) != NULL) {
    v1 = atoi(buffer);
    i = 0;
    while (isdigit(buffer[i])) i++;
    while (buffer[i] == ' ') i++;
    v2 = atoi(&buffer[i]);
    while (isdigit(buffer[i])) i++;
    if (buffer[i] == ' ') { // There is a distance
      while (buffer[i] == ' ') i++;
      dist = atoi(&buffer[i]);
    }
    else dist = 1;
    G->setEdge(v1, v2, dist);
    if (undirected) // Put in edge in other direction
      G->setEdge(v2, v1, dist);
  }
  return G;
}
Exemplo n.º 13
0
/** 
 * Read 1-gram data from RL 3-gram file.  Only the back-off weights are
 * stored.
 * 
 * @param fp [in] file pointer
 * @param ndata [out] N-gram to store the read data.
 */
static boolean
add_unigram(FILE *fp, NGRAM_INFO *ndata)
{
  WORD_ID read_word_num;
  WORD_ID nid;
  LOGPROB prob, bo_wt;
  char *name, *p;
  boolean ok_p = TRUE;
  boolean mismatched = FALSE;

  ndata->bo_wt_1 = (LOGPROB *)mymalloc_big(sizeof(LOGPROB), ndata->max_word_num);

  read_word_num = 0;
  while (getl(buf, sizeof(buf), fp) != NULL && buf[0] != '\\') {
    if ((p = strtok(buf, DELM)) == NULL) {
      jlog("Error: ngram_read_arpa: RL 1-gram: failed to parse, corrupted or invalid data?\n");
      return FALSE;
    }
    prob = atof(p);
    if ((p = strtok(NULL, DELM)) == NULL) {
      jlog("Error: ngram_read_arpa: RL 1-gram: failed to parse, corrupted or invalid data?\n");
      return FALSE;
    }
    name = strcpy((char *)mymalloc(strlen(p)+1), p);
    if ((p = strtok(NULL, DELM)) == NULL) {
      bo_wt = 0.0;
    } else {
      bo_wt = (LOGPROB)atof(p);
    }

    /* add bo_wt_rl to existing 1-gram entry */
    nid = ngram_lookup_word(ndata, name);
    if (nid == WORD_INVALID) {
      if (mismatched == FALSE) {
	jlog("Error: ngram_read_arpa: vocabulary mismatch between LR n-gram and RL n-gram\n");
	mismatched = TRUE;
      }
      jlog("Error: ngram_read_arpa: \"%s\" does not appears in LR n-gram\n", name);
      ok_p = FALSE;
    } else {
      ndata->bo_wt_1[nid] = bo_wt;
    }
  
    read_word_num++;
    if (read_word_num > ndata->max_word_num) {
      jlog("Error: ngram_read_arpa: vocabulary size of RL n-gram is bigger than header value (%d)\n", ndata->max_word_num);
      return FALSE;
    }
    free(name);
  }
  if (ok_p == TRUE) {
    jlog("Stat: ngram_read_arpa: read %d 1-gram entries\n", read_word_num);
  }

  return ok_p;
}
Exemplo n.º 14
0
void WEXPORT WObjectFile::readObject( unsigned char* obj )
{
    if( _version <= 38 ) {
        *obj = getch();
    } else {
        /* changed to use text format */
        *obj = (unsigned char)getl();
    }
    readEOItem();
}
Exemplo n.º 15
0
int
main()
{
    int len=0;
    int t=0;
    int brace=0, bracket=0, parenthesis=0;
    int s_quote=1, d_quote=1;
    
    
    while ((len = getl()) > 0 )
    {
        t=0;
        while(t < len)
        {
            if( line[t] == '[')
            {
                brace++;
            }
            if( line[t] == ']')
            {
                brace--;
            }
            if( line[t] == '(')
            {
                parenthesis++;
            }
            if( line[t] == ')')
            {
                parenthesis--;
            }
            if( line[t] == '\'')
            {
                s_quote *= -1;
            }
            if( line[t] == '"')
            {
                d_quote *= -1;
            }
            t++;
        }
    }
    if(d_quote !=1)
        printf ("Mismatching double quote mark\n");
    if(s_quote !=1)
        printf ("Mismatching single quote mark\n");
    if(parenthesis != 0)
        printf ("Mismatching parenthesis\n");
    if(brace != 0)
        printf ("Mismatching brace mark\n");
    if(bracket != 0)
        printf ("Mismatching bracket mark\n");
    if( bracket==0 && brace==0 && parenthesis==0 && s_quote == 1 && d_quote == 1)
        printf ("Syntax appears to be correct.\n");
    return 0;
}
Exemplo n.º 16
0
int main() {
  char line[MAXLINE];
  int found = 0;
  while (getl(line, MAXLINE) > 0) {
    if (strrindex(line, "abba") >= 0) {
      printf("%s", line);
      found++;
    }
  }
  return found;
}
Exemplo n.º 17
0
	/* synch on C successive matches */
static int
easysynch()
{
	int i, j;
	int k, m;
	char *s0, *s1;

	for (i = j = 1; i < RANGE && j < RANGE; i++, j++) {
		s0 = getl(0, n0+i);
		if (s0 == NULL)
			return (output(INF, INF));
		for (k = C-1; k < j; k++) {
			for (m = 0; m < C; m++)
				if (cmp(getl(0, n0+i-m),
					getl(1, n1+k-m)) != 0)
					goto cont1;
			return (output(i-C, k-C));
cont1:
			;
		}
		s1 = getl(1, n1+j);
		if (s1 == NULL)
			return (output(INF, INF));
		for (k = C-1; k <= i; k++) {
			for (m = 0; m < C; m++)
				if (cmp(getl(0, n0+k-m),
					getl(1, n1+j-m)) != 0)
					goto cont2;
			return (output(k-C, j-C));
cont2:
			;
		}
	}
	return (0);
}
Exemplo n.º 18
0
static PyObject *
PWM_get_polarity(PWM * self) {
    char cpol[2];
    PyObject * i;

    getl(self->fd_polarity, &cpol[0]);
    i = PyInt_FromString(&cpol[0], NULL, 10);

    //printf("get_polarity() returning %i.\n", PyInt_AsLong(i));
    Py_INCREF(i);
    return i;

}
Exemplo n.º 19
0
static PyObject *
getDirection(GPIO * self) {

	PyObject * res;
	char buf[5];		// in, out, low or high

	getl(self->fd_dir, &buf[0]);

	res = PyBytes_FromString(&buf[0]);

	Py_INCREF(res);
	return res;
}
Exemplo n.º 20
0
static PyObject *
getTrigger(GPIO * self) {

	PyObject * res;
	char buf[10];

	getl(self->fd_edge, &buf[0]);

	res = PyBytes_FromString(&buf[0]);

	Py_INCREF(res);
	return res;
}
Exemplo n.º 21
0
static PyObject *
GPIO_get_value(GPIO * self) {
	int dirfd;
	char cval[2];
	PyObject * i;

	getl(self->fd_val, &cval[0]);
	i = PyInt_FromString(&cval[0], NULL, 10);
	
	// printf("\nget_value() returning %i (%i)\n", cval[0] - 48, PyInt_AsLong(i));
	return i;

}
Exemplo n.º 22
0
/**
 * Top function to read word list via text
 *
 * @param fp [in] file pointer
 * @param winfo [out] pointer to word dictionary to store the read data.
 * @param hmminfo [in] HTK %HMM definition data.  if NULL, phonemes are ignored.
 * @param headphone [in] word head silence model name
 * @param tailphone [in] word tail silence model name
 * @param contextphone [in] silence context name to be used at head and tail
 *
 * @return TRUE on success, FALSE on any error word.
 */
boolean
voca_load_wordlist(FILE *fp, WORD_INFO *winfo, HTK_HMM_INFO *hmminfo, char *headphone, char *tailphone, char *contextphone)
{
    boolean ret;

    voca_load_start(winfo, hmminfo, FALSE);
    while (getl(buf, sizeof(buf), fp) != NULL) {
        if (voca_load_word_line(buf, winfo, hmminfo, headphone, tailphone, contextphone) == FALSE) break;
    }
    ret = voca_load_end(winfo);

    return(ret);
}
Exemplo n.º 23
0
static PyObject *
PWM_get_period(PWM * self) {
    char cprd[10];
    PyObject * i;

    getl(self->fd_period, &cprd[0]);
    i = PyInt_FromString(&cprd[0], NULL, 10);

    //printf("\nget_period() returning %i.\n", PyInt_AsLong(i));
    Py_INCREF(i);
    return i;

}
Exemplo n.º 24
0
/*
 * File Name Entry
 */
int input_file_name(void)
{
	char buf[13];
	int res;

	MZ_msg(0,0,"PLEASE ENTER FILE NAME");
	res=getl(0,1,8,buf);
	if(res>0){
		buf[res]='.'; buf[res+1]='M'; buf[res+2]='Z'; buf[res+3]='T'; buf[res+4]='\0';
		strcpy(tname, buf);
	}
	return(res);
}
Exemplo n.º 25
0
/**
 * read_phy_reg - MII interface  to read  @reg_addr register of phy at @phy_addr
 * return positive and zero value if success, or negative value if fail
 * may be used by other standard ethernet phy
 */
unsigned short read_phy_reg_sr8201g(ec_priv_t * ecp, unsigned short reg_addr)
{
	u32 op_reg;
	u32 phy_addr;
	if((ecp->phy_addr)!=0xFF)
		phy_addr=ecp->phy_addr;
	else
		phy_addr=ASOC_ETHERNET_PHY_ADDR;

	do {
		op_reg = getl(MAC_CSR10);
	} while (op_reg & MII_MNG_SB);

	putl(MII_MNG_SB | MII_MNG_OPCODE(MII_OP_READ) | MII_MNG_REGADD(reg_addr) |
		MII_MNG_PHYADD(phy_addr), MAC_CSR10);

	do {
		op_reg = getl(MAC_CSR10);
	} while (op_reg & MII_MNG_SB);

	return (u16)MII_MNG_DATA(op_reg);
}
Exemplo n.º 26
0
/**
 * Top function to read word dictionary via file pointer (gzip enabled)
 *
 * @param fp [in] file pointer
 * @param winfo [out] pointer to word dictionary to store the read data.
 * @param hmminfo [in] HTK %HMM definition data.  if NULL, phonemes are ignored.
 * @param ignore_tri_conv [in] TRUE if triphone conversion is ignored
 *
 * @return TRUE on success, FALSE on any error word.
 */
boolean
voca_load_htkdict(FILE *fp, WORD_INFO *winfo, HTK_HMM_INFO *hmminfo, boolean ignore_tri_conv)
{
    boolean ret;

    voca_load_start(winfo, hmminfo, ignore_tri_conv);
    while (getl(buf, sizeof(buf), fp) != NULL) {
        if (voca_load_line(buf, winfo, hmminfo) == FALSE) break;
    }
    ret = voca_load_end(winfo);

    return(ret);
}
Exemplo n.º 27
0
int main() {

	char *charbufer;
	int n;

	n =  getl(&charbufer);
	if (n > 0) {
		printf("%d\n" , n);
		puts(charbufer);
	}

	return(0);
}
Exemplo n.º 28
0
Arquivo: button.c Projeto: wtok/ktane
char const *
button(void)
{
	printf("[b]lue, [r]ed, [w]hite, [y]ellow.\n");
	printf("What colour is the button?\n");
	printf("Enter a colour: ");
	char colour_str[2] = {0};
	getl(colour_str, 1);

	printf("[a]bort, [d]etonate, [h]old.\n");
	printf("What text is on the button?\n");
	printf("Enter text: ");
	char text_str[2] = {0};
	getl(text_str, 1);

	char const colour = colour_str[0];
	char const   text =   text_str[0];

	if (colour == 'b' && text == 'a')
		return hold_the_button();

	if (text == 'd' && num_batteries() > 1)
		return "Press and release.";

	if (colour == 'w' && have_lit_car())
		return hold_the_button();

	if (num_batteries() > 2 && have_lit_frk())
		return "Press and release.";

	if (colour == 'y')
		return hold_the_button();

	if (colour == 'r' && text == 'h')
		return "Press and release.";

	return hold_the_button();
}
Exemplo n.º 29
0
int main(void) {
	int len;
	int max;

	max = 0;
	while ((len = getl()) > 0)
		if (len > max)
			max = len;
	if (max > 0)
		printf("%d ", max);

	getchar();
	return 0;
}
Exemplo n.º 30
0
/**
 * write_phy_reg - MII interface  to write  @val to @reg_addr register of phy at @phy_addr
 * return zero if success, negative value if fail
 * may be used by other standard ethernet phy
 */
int write_phy_reg_sr8201g(ec_priv_t * ecp, unsigned short reg_addr, unsigned short val)
{
	u32 op_reg;
	u32 phy_addr;

	if((ecp->phy_addr)!=0xFF)
		phy_addr=ecp->phy_addr;
	else
		phy_addr=ASOC_ETHERNET_PHY_ADDR;

	do {
		op_reg = getl(MAC_CSR10);
	} while (op_reg & MII_MNG_SB);

	putl(MII_MNG_SB | MII_MNG_OPCODE(MII_OP_WRITE) | MII_MNG_REGADD(reg_addr) |
		MII_MNG_PHYADD(phy_addr) | val, MAC_CSR10);

	do {
		op_reg = getl(MAC_CSR10);
	} while (op_reg & MII_MNG_SB);

	return 0;
}