コード例 #1
0
ファイル: init.c プロジェクト: Claruarius/stblinux-2.6.37
int
main(
	int	argc,
	char	**argv)
{
	int	c, i, done = 0;
	char	*input;
	char	**v;

	pushfile(stdin);
	init(argc, argv);

	for (i = 0; !done && i < ncmdline; i++) {
		v = breakline(cmdline[i], &c);
		if (c)
			done = command(c, v);
		xfree(v);
	}
	if (cmdline) {
		xfree(cmdline);
		return exitcode;
	}

	while (!done) {
		if ((input = fetchline()) == NULL)
			break;
		v = breakline(input, &c);
		if (c)
			done = command(c, v);
		doneline(input, v);
	}
	return exitcode;
}
コード例 #2
0
ファイル: command.c プロジェクト: chandanr/xfsprogs-dev
void
command_loop(void)
{
	int		c, i, j = 0, done = 0;
	char		*input;
	char		**v;
	const cmdinfo_t	*ct;

	for (i = 0; !done && i < ncmdline; i++) {
		input = strdup(cmdline[i]);
		if (!input) {
			fprintf(stderr,
				_("cannot strdup command '%s': %s\n"),
				cmdline[i], strerror(errno));
			exit(1);
		}
		v = breakline(input, &c);
		if (c) {
			ct = find_command(v[0]);
			if (ct) {
				if (ct->flags & CMD_FLAG_GLOBAL)
					done = command(ct, c, v);
				else {
					j = 0;
					while (!done && (j = args_command(j)))
						done = command(ct, c, v);
				}
			} else
				fprintf(stderr, _("command \"%s\" not found\n"),
					v[0]);
		}
		doneline(input, v);
	}
	if (cmdline) {
		free(cmdline);
		return;
	}
	while (!done) {
		if ((input = fetchline()) == NULL)
			break;
		v = breakline(input, &c);
		if (c) {
			ct = find_command(v[0]);
			if (ct)
				done = command(ct, c, v);
			else
				fprintf(stderr, _("command \"%s\" not found\n"),
					v[0]);
		}
		doneline(input, v);
	}
}
コード例 #3
0
ファイル: renderer.c プロジェクト: Orc/ndialog
/*
 * addword() adds a word to the rendered page, breaking the line as
 * appropriate.
 */
void
addword(char *word)
{
    int siz = strlen(word);
    char *p;

    switch (state.doing) {
    case D_PRE:
	addstring((unsigned char*)word);
	break;
    case D_TITLE:
	state.page->titlelen += siz;
	state.page->title = realloc(state.page->title, state.page->titlelen+2);
	strcat(state.page->title, word);
	break;
    default:
	if (XP + siz > state.width)
	    breakline();
	if (state.style & St_CAPS) {
	    for (p=word; *p; ++p)
		*p = toupper(*p);
	}
	linestart();

	addstring((unsigned char*)word);
	XP += siz;
	break;
    }
    LASTWASSPACE = 0;
} /* addword */
コード例 #4
0
ファイル: getpwent.c プロジェクト: jobermayr/cdrtools
EXPORT struct passwd *
getpwent()
{
	char	*arr[7];

	if (pwdf == (FILE *)NULL) {
		pwdf = fileopen("/etc/passwd", "r");
		if (pwdf == (FILE *)NULL)
			return ((struct passwd *)0);
	}
	if (fgetline(pwdf, pwdbuf, sizeof (pwdbuf)) == EOF)
		return ((struct passwd *)0);
	breakline(pwdbuf, ':', arr, 7);
	return (mkpwd(arr));
}
コード例 #5
0
 bool authenticate_author(Request req)
 {
   FILE   *in;
   char   *lines[10];
   size_t  cnt;
   
   assert(req         != NULL);
   assert(req->author != NULL);
   
   if (c_authorfile == NULL)
     return strcmp(req->author,c_author) == 0;
     
   in = fopen(c_authorfile,"r");
   if (in == NULL)
   {
     syslog(LOG_ERR,"%s: %s",c_authorfile,strerror(errno));
     return false;
   }
   
   while((cnt = breakline(lines,10,in)))
   {
     if ((c_af_uid < cnt) && (strcmp(req->author,lines[c_af_uid]) == 0))
     {
       /*----------------------------------------------
       ; A potential memory leak---see the comment above in
       ; the USE_DB version of this routine
       ;----------------------------------------------------*/
       
       if (c_af_name < cnt)
       {
         req->author = strdup(lines[c_af_name]);
         fclose(in);
         free(lines[0]); // see comment below
         return true;
       }
     }
     
     /*------------------------------------------------------------------
     ; Some tight coupling between this routine and breakline().  The first
     ; element of lines[] needs to be freed, but not the rest.
     ;--------------------------------------------------------------------*/
     
     free(lines[0]);
   }
   
   fclose(in);
   return false;
 }
コード例 #6
0
ファイル: renderer.c プロジェクト: Orc/ndialog
/*
 * addspace() adds space to the rendered page, breaking the line as appropriate
 */
void
addspace(char *space)
{
    switch (state.doing) {
    case D_PRE:
	    /* when doing a PRE segment, we need to catch \n's and properly
	     * expand them into \n, DLE, ' ' */
	    while (*space) {
		if (*space == '\n')
		    addnewline();
		else {
		    linestart();
		    addchar(*space);
		}
		++space;
	    }
	    break;
    case D_TITLE:
	    if (!LASTWASSPACE) {
		state.page->titlelen++;
		state.page->title = realloc(state.page->title,
					    state.page->titlelen+2);
		strcat(state.page->title, " ");
	    }
	    break;
    default:
	    if (!LASTWASSPACE) {
		if (XP >= state.width)
		    breakline();
		else if (XP > 0) {
		    linestart();
		    addchar(' ');
		    XP++;
		}
	    }
	    break;
    }
    LASTWASSPACE = 1;
} /* addspace */
コード例 #7
0
 bool authenticate_author(Request req)
 {
   char   *lines[10];
   size_t  cnt;
   DB     *list;
   DBT     key;
   DBT     data;
   int     rc;
   
   assert(req         != NULL);
   assert(req->author != NULL);
   
   /*--------------------------------------------------------------
   ; this version will replace the login name with the full name,
   ; assuming it's defined in the database file as the (hardcoded)
   ; third field of the value portion returned.
   ;---------------------------------------------------------------*/
   
   if (c_authorfile == NULL)
     return  strcmp(req->author,c_author) == 0;
     
   list = dbopen(c_authorfile,O_RDONLY,0644,DB_HASH,NULL);
   if (list == NULL)
     return false;
     
   key.data = req->author;
   key.size = strlen(req->author);
   rc       = (list->get)(list,&key,&data,0);
   (list->close)(list);
   if (rc) return false;
   
   cnt        = breakline(lines,10,data.data);
   req->athor = strdup(lines[c_af_name]);
   free(lines[0]);
   
   return true;
 }
コード例 #8
0
ファイル: cmd.c プロジェクト: 0bliv10n/s2e
void command_loop(void)
{
    int c, i, j = 0, done = 0, fetchable = 0, prompted = 0;
    char *input;
    char **v;
    const cmdinfo_t *ct;

    for (i = 0; !done && i < ncmdline; i++) {
        input = strdup(cmdline[i]);
        if (!input) {
            fprintf(stderr, _("cannot strdup command '%s': %s\n"),
                    cmdline[i], strerror(errno));
            exit(1);
        }
        v = breakline(input, &c);
        if (c) {
            ct = find_command(v[0]);
            if (ct) {
                if (ct->flags & CMD_FLAG_GLOBAL) {
                    done = command(ct, c, v);
                } else {
                    j = 0;
                    while (!done && (j = args_command(j))) {
                        done = command(ct, c, v);
                    }
                }
            } else {
                fprintf(stderr, _("command \"%s\" not found\n"), v[0]);
            }
	}
        doneline(input, v);
    }
    if (cmdline) {
        g_free(cmdline);
        return;
    }

    while (!done) {
        if (!prompted) {
            printf("%s", get_prompt());
            fflush(stdout);
            qemu_aio_set_fd_handler(STDIN_FILENO, prep_fetchline, NULL, NULL,
                                    NULL, &fetchable);
            prompted = 1;
        }

        qemu_aio_wait();

        if (!fetchable) {
            continue;
        }
        input = fetchline();
        if (input == NULL) {
            break;
        }
        v = breakline(input, &c);
        if (c) {
            ct = find_command(v[0]);
            if (ct) {
                done = command(ct, c, v);
            } else {
                fprintf(stderr, _("command \"%s\" not found\n"), v[0]);
            }
        }
        doneline(input, v);

        prompted = 0;
        fetchable = 0;
    }
    qemu_aio_set_fd_handler(STDIN_FILENO, NULL, NULL, NULL, NULL, NULL);
}