Ejemplo n.º 1
0
main()
{
	char s1[MAXLINE],s2[MAXLINE];

	printf("Please enter s2: \n");
	if(getline_(s2,MAXLINE) < 1)
		return 0;
	while(getline_(s1,MAXLINE))
		printf("%d \n",any(s1,s2));
}
Ejemplo n.º 2
0
static void traceexec (lua_State *L, const Instruction *pc) {
  lu_byte mask = L->hookmask;
  const Instruction *oldpc = L->savedpc;
  L->savedpc = pc;
  if ((mask & LUA_MASKCOUNT) && L->hookcount == 0) {
    resethookcount(L);
    luaD_callhook(L, LUA_HOOKCOUNT, -1);
  }
  if (mask & LUA_MASKLINE) {
    Proto *p = ci_func(L->ci)->l.p;
    int npc = pcRel(pc, p);
    int newline = getline_(p, npc);
    /* call linehook when enter a new function, when jump back (loop),
       or when enter a new line */
    if (npc == 0 || pc <= oldpc || newline != getline_(p, pcRel(oldpc, p)))
      luaD_callhook(L, LUA_HOOKLINE, newline);
  }
}
Ejemplo n.º 3
0
main()
{
	char line[MAXLINE];
	
	while(getline_(line,MAXLINE) > 0) {
		reverse(line);
		printf("%s",line);
	}
	return 0;
}
Ejemplo n.º 4
0
int main ()
{
  char line[MAXLINE];
  int i;

  while (getline_(line, MAXLINE) > 0)
    if (trim(line, MAXLINE) != -1)
      printf("%s\n", line);

  return 0;
}
Ejemplo n.º 5
0
static struct ddb_entry *read_file(const char *fname,
        struct ddb_entry *key, uint32_t *num_values)
{
        FILE *f;
        size_t lc = 0;
        size_t r = 0;
        char *line = NULL;
        size_t len = 0;

        if (!(f = fopen(fname, "r"))){
                fprintf(stderr, "Couldn't open %s\n", fname);
                exit(1);
        }

        struct ddb_entry *values = NULL;

        while ((r = getline_(&line, &len, f)) != -1) {
                lc++;
                free(line);
                line = NULL;
        }
        if (lc < 1){
                fprintf(stderr, "Not enough lines in %s.\n", fname);
                fprintf(stderr, "At least one line (key) is needed. The next lines should contain values.\n");
                exit(1);
        }
        rewind(f);
        key->length = getline_((char**)&key->data, &len, f) - 1;
        values = calloc(1, (lc - 1) * sizeof(struct ddb_entry));
        lc = 0;
        while ((r = getline_((char**)&values[lc].data, &len, f)) != -1){
                values[lc].length = r - 1;
                ++lc;
        }
        *num_values = lc;
        fclose(f);
        return values;
}
Ejemplo n.º 6
0
int readlines(char *lineptr[], int maxlines)
{
    int len, nlines;
    char *p, line[MAXLEN];
    nlines = 0;
    while ((len = getline_(line, MAXLEN)) > 0)
        if (nlines >= maxlines || (p = alloc(len)) == NULL)
            return -1;
        else {
            line[len - 1] = '\0';
            strcpy(p, line);
            lineptr[nlines++] = p;
        }
    return nlines;
}
Ejemplo n.º 7
0
int main(void)
{
	//char s[] = "2233432.23242";
	double  sum, atof_( char []);
	
	char line[MAXLINE];
	int getline_(char line[], int max);
	
	sum = 0;
	while (getline_( line, MAXLINE ) > 0 ){
		printf("\t%g\n",sum += atof_(line));
	}

	return 0;
}
Ejemplo n.º 8
0
main()
{
	int len;
	extern int max;
	extern char longest[];

	max = 0;
	while((len = getline_()) > 0)
		if(len > max) {
			max = len;
			copy();
		}
	if(max > 0)
		printf("%s",longest);
	return 0;
}
Ejemplo n.º 9
0
/* print the longest input line */
main()
{
	int len; 				/* current line length */
	int max; 				/* maximum length seen so far */
	char line[MAXLINE]; 	/* current input line */
	char longest[MAXLINE]; 	/* longest line saved here */
	max = 0;
	while ((len = getline_(line, MAXLINE)) > 0)
		if (len > max) {
		max = len;
		copy(longest, line);
		}
	if (max > 0) 		/* there was a line */
		printf("%s", longest);
	return 0;
}
/*imprime la linea de entrada mas larga*/
main()
{
	int len;		/*longitud actual de la linea*/
	int max;		/*maxima longitud vista hasta el momento*/
	char line[MAXLINE];	/*LINEA DE ENTRADA ACTUAL*/
	char longest[MAXLINE];	/*LA LINEA MAS LARGA SE GUARDA AQUI*/
	
	max=0;
	while ((len=getline_(line,MAXLINE))>0){
	
		if (len>max){
			max=len;
			copy_(longest,line);
		}
	}
	if(max>0)		/*hubo una linea*/
		printf("%s",longest);
	return 0;
	
}
Ejemplo n.º 11
0
int parse_file(char*** dst, int* size, const char* filename)
{
    FILE *file = NULL;
    int i = 0;
    char *p = NULL;

    if (filename == NULL || dst==NULL || size==NULL)
        return 1;

    file = fopen(filename, "r");
    if (file == NULL)
        return 1;
    
    *size = 4;
    *dst = (char **) malloc(sizeof(char*) * (*size)); 
    while ( (p = getline_(file)) != NULL )
    {
        if (i > *size - 1)
        { 
           *size = *size << 1;
           *dst = (char **) realloc(*dst, *size * sizeof(char*));
        }
        (*dst)[i++] = p;   
    }
    
    if (i==0)
    {
       free(*dst);
       *dst = NULL;
       *size = 0;
    }   
    else
    {
       *size = i; 
    }
    
    fclose(file);

    return 0;
}
Ejemplo n.º 12
0
/* Read a line, processing commands (lines that start with a backslash
 * (that isn't the start of a special character)), and write the
 * first non-command to s.
 * Return true if timed-out.  */
static bool dumb_read_line(char *s, char *prompt, bool show_cursor,
			   int timeout, enum input_type type,
			   zchar *continued_line_chars)
{
  time_t start_time;

  if (timeout) {
    if (time_ahead >= timeout) {
      time_ahead -= timeout;
      return TRUE;
    }
    timeout -= time_ahead;
    start_time = time(0);
  }
  time_ahead = 0;

  dumb_show_screen(show_cursor);
  for (;;) {
    char *command;
    if (prompt)
      fputs(prompt, stdout);
    else
      dumb_show_prompt(show_cursor, (timeout ? "tTD" : ")>}")[type]);
    getline_(s);
    if ((s[0] != '\\') || ((s[1] != '\0') && !islower(s[1]))) {
      /* Is not a command line.  */
      translate_special_chars(s);
      if (timeout) {
	int elapsed = (time(0) - start_time) * 10 * speed;
	if (elapsed > timeout) {
	  time_ahead = elapsed - timeout;
	  return TRUE;
	}
      }
      return FALSE;
    }
    /* Commands.  */

    /* Remove the \ and the terminating newline.  */
    command = s + 1;
    command[strlen(command) - 1] = '\0';
    
    if (!strcmp(command, "t")) {
      if (timeout) {
	time_ahead = 0;
	s[0] = '\0';
	return TRUE;
      }
    } else if (*command == 'w') {
      if (timeout) {
	int elapsed = atoi(&command[1]);
	time_t now = time(0);
	if (elapsed == 0)
	  elapsed = (now - start_time) * 10 * speed;
	if (elapsed >= timeout) {
	  time_ahead = elapsed - timeout;
	  s[0] = '\0';
	  return TRUE;
	}
	timeout -= elapsed;
	start_time = now;
      }
    } else if (!strcmp(command, "d")) {
      if (type != INPUT_LINE_CONTINUED)
	fprintf(stderr, "DUMB-FROTZ: No input to discard\n");
      else {
	dumb_discard_old_input(strlen((char *) continued_line_chars));
	continued_line_chars[0] = '\0';
	type = INPUT_LINE;
      }
    } else if (!strcmp(command, "help")) {
      if (!do_more_prompts)
	fputs(runtime_usage, stdout);
      else {
	char *current_page, *next_page;
	current_page = next_page = runtime_usage;
	for (;;) {
	  int i;
	  for (i = 0; (i < h_screen_rows - 2) && *next_page; i++)
	    next_page = strchr(next_page, '\n') + 1;
	  printf("%.*s", (int) (next_page - current_page), current_page);
	  current_page = next_page;
	  if (!*current_page)
	    break;
	  printf("HELP: Type <return> for more, or q <return> to stop: ");
	  getline_(s);
	  if (!strcmp(s, "q\n"))
	    break;
	}
      }
    } else if (!strcmp(command, "s")) {
	dumb_dump_screen();
    } else if (!dumb_handle_setting(command, show_cursor, FALSE)) {
      fprintf(stderr, "DUMB-FROTZ: unknown command: %s\n", s);
      fprintf(stderr, "Enter \\help to see the list of commands\n");
    }
  }
}
Ejemplo n.º 13
0
static void PrintCode(const Proto* f)
{
 const Instruction* code=f->code;
 int pc,n=f->sizecode;
 for (pc=0; pc<n; pc++)
 {
  Instruction i=code[pc];
  OpCode o=GET_OPCODE(i);
  int a=GETARG_A(i);
  int b=GETARG_B(i);
  int c=GETARG_C(i);
  int bx=GETARG_Bx(i);
  int sbx=GETARG_sBx(i);
  int line=getline_(f,pc);
  printf("\t%d\t",pc+1);
  if (line>0) printf("[%d]\t",line); else printf("[-]\t");
  printf("%-9s\t",luaP_opnames[o]);
  switch (getOpMode(o))
  {
   case iABC:
    printf("%d",a);
    if (getBMode(o)!=OpArgN) printf(" %d",ISK(b) ? (-1-INDEXK(b)) : b);
    if (getCMode(o)!=OpArgN) printf(" %d",ISK(c) ? (-1-INDEXK(c)) : c);
    break;
   case iABx:
    if (getBMode(o)==OpArgK) printf("%d %d",a,-1-bx); else printf("%d %d",a,bx);
    break;
   case iAsBx:
    if (o==OP_JMP) printf("%d",sbx); else printf("%d %d",a,sbx);
    break;
  }
  switch (o)
  {
   case OP_LOADK:
    printf("\t; "); PrintConstant(f,bx);
    break;
   case OP_GETUPVAL:
   case OP_SETUPVAL:
    printf("\t; %s", (f->sizeupvalues>0) ? getstr(f->upvalues[b]) : "-");
    break;
   case OP_GETGLOBAL:
   case OP_SETGLOBAL:
    printf("\t; %s",svalue(&f->k[bx]));
    break;
   case OP_GETTABLE:
   case OP_SELF:
    if (ISK(c)) { printf("\t; "); PrintConstant(f,INDEXK(c)); }
    break;
   case OP_SETTABLE:
   case OP_ADD:
   case OP_SUB:
   case OP_MUL:
   case OP_DIV:
   case OP_POW:
   case OP_EQ:
   case OP_LT:
   case OP_LE:
    if (ISK(b) || ISK(c))
    {
     printf("\t; ");
     if (ISK(b)) PrintConstant(f,INDEXK(b)); else printf("-");
     printf(" ");
     if (ISK(c)) PrintConstant(f,INDEXK(c)); else printf("-");
    }
    break;
   case OP_JMP:
   case OP_FORLOOP:
   case OP_FORPREP:
    printf("\t; to %d",sbx+pc+2);
    break;
   case OP_CLOSURE:
    printf("\t; %p",VOID(f->p[bx]));
    break;
   case OP_SETLIST:
    if (c==0) printf("\t; %d",(int)code[++pc]);
    else printf("\t; %d",c);
    break;
   default:
    break;
  }
  printf("\n");
 }
}