Esempio n. 1
0
File: downboy2.c Progetto: anl/IT
void read_stat(char *proc_id,override_type *entry,int k,int uid)
{
   char *stat_filename=make_name(proc_id,1);
   int done=0;

   char *field;
   FILE *fp;
   int n; /* current field number */

   char *proc_name;
   unsigned utime;
   int priority;
   int nice;

   if ((fp=fopen(stat_filename,"r"))==NULL)
      fprintf(stderr,"Error: failed to open '%s'!\n",stat_filename);
   else
      {
      for (n=0; !done && (field=get_next_field(fp)); n++)
         switch (n)
            {
            case 1: /* proc name */
               proc_name=alloca(strlen(field)+1);
               strcpy(proc_name,strip_parens(field));
               break;

            case 13: /* utime */
               utime=atol(field)/(float)USER_HZ;
               break;

            case 17: /* priority */
               priority=atoi(field);
               break;

            case 18: /* nice */
               nice=atoi(field);
               done=1; /* end iteration after last interesting field */
               break;
            }

      fclose(fp);
      }

   if (done) /* reached last field OK */
      {
      /* if exceeded defined kill threshold and not an exception... */
      if (k>0 && (!entry || entry->elapsed!=-1) && utime>k)
         kill_proc(atoi(proc_id),uid,k);
      else
         adjust_sched(atoi(proc_id),proc_name,utime,priority,nice,entry);
      }
}
Esempio n. 2
0
File: alias.c Progetto: wfp5p/elm
static int add_current_alias(void)
{
/*
 *	Alias the current message to the specified name and
 *	add it to the alias text file, for processing as
 *	the user leaves the program.
 *
 *	Returns non-zero iff alias actually added to file.
 */

	char aliasname[SLEN], firstname[SLEN], lastname[SLEN];
	char comment[SLEN], address1[LONG_STRING], buffer[SLEN];
	char comment_buff[LONG_STRING];
	char *chspace, *bufptr;
	struct header_rec *current_header;

	static char bad_punc[] = ",.:;";
	char *punc_ptr;
	int i, match;
	int replace, to_replace;

	if (curr_folder.curr_mssg == 0) {
	 dprint(4, (debugfile,
		"Add current alias called without any current message!\n"));
	 show_error(catgets(elm_msg_cat, AliasesSet, AliasesNoMessage,
		"No message to alias to!"));
	 return(0);
	}
	current_header = curr_folder.headers[curr_folder.curr_mssg-1];

	strcpy(buffer, catgets(elm_msg_cat, AliasesSet, AliasesCurrentMessage,
		"Current message address aliased to: "));
	PutLine(LINES-2,0, buffer);
	CleartoEOLN();
	*aliasname = '\0';
	if ((replace = get_aliasname(aliasname, buffer, &to_replace)) < 0) {
	    dprint(3, (debugfile,
	        "Aliasname [%s] was rejected in add_current_alias\n",
	        aliasname));
	    ClearLine(LINES-2);
	    return(0);
	}

	/* use full name in current message for default comment */
	tail_of(current_header->from, comment_buff, current_header->to);
	if(strchr(comment_buff, (int)'!') || strchr(comment_buff, (int)'@'))
	  /* never mind - it's an address not a full name */
	  *comment_buff = '\0';

/*
 *	Try to break up the From: comment into firstname, lastname, and
 *	any other text.  This is based on the fact that many address
 *	comments are pretty straightforward.  This will break on many
 *	situations.  Should handle:
 *		(Robert Howard)
 *		(Robert L. Howard)
 *		(Robert Howard, Georgia Tech)
 *	pretty well.  Will break on:
 *		(The Voice of Reason)
 *		and others....
 */

	*firstname = '\0';
	*lastname = '\0';
	*comment = '\0';
	if (strlen(comment_buff) != 0) {	/* There is something. */
	    bufptr = comment_buff;
	    while (*bufptr == ' ') bufptr++;	/* Always strip leading WS */
	    if ((chspace = strchr(bufptr, ' ')) != NULL) {
	   /*
	    *   A space means that there is at least (firstname lastname)
	    *   Get firstname and move bufptr.
	    */
	        *chspace = '\0';
	        strcpy(firstname, bufptr);
	        bufptr = chspace + 1;			/* Move the pointer */
	        while (*bufptr == ' ') bufptr++;
	    }

above:	    if ((chspace = strchr(bufptr, ' ')) != NULL) {
	   /*
	    *   Another space means a third+ word.  We either have:
	    *       1. Word 3+ is a comment, or
	    *       2. Word 2 is a middle initial (word 3 is lastname).
	    *   Check and see.
	    */
	        *chspace = '\0';
	        if ((strlen(bufptr) == 1) ||
	            (strlen(bufptr) == 2  && *(bufptr+1) == '.')) {
	       /*
	        *   If the second word is either a single
	        *   character or a character followed by '.' it was
	        *   probably a middle initial.  Add it to firstname
	        *   and shift.
	        */
	            strcat(firstname, " ");
	            strcat(firstname, bufptr);
	            bufptr = chspace + 1;		/* Move the pointer */
	            while (*bufptr == ' ') bufptr++;
	            goto above;
	        }
	        strcpy(lastname, bufptr);
	        bufptr = chspace + 1;			/* Move the pointer */
	        while (*bufptr == ' ') bufptr++;
	        strcpy(comment, bufptr);
	    }
	    else {
	   /*
	    *   Only a lastname left.
	    */
	        strcpy(lastname, bufptr);
	    }

	/*
	 *  Finally, get any puctuation characters off the end of
	 *  lastname.
	 */
	    match = TRUE;
	    for (i = strlen(lastname) - 1; match && i>0; i--) {
	        match = FALSE;
	        for (punc_ptr = bad_punc; *punc_ptr != '\0'; punc_ptr++) {
	            if (lastname[i] == *punc_ptr) {
	                lastname[i] = '\0';
	                match = TRUE;
	                break;
	            }
	        }
	    }
	}

	get_realnames(aliasname, firstname, lastname, comment, buffer);

	/* grab the return address of this message */
	get_return(address1, curr_folder.curr_mssg-1);
	strcpy(address1, strip_parens(address1));	/* remove parens! */

	return(ask_accept(aliasname, firstname, lastname, comment, address1,
	        buffer, replace, to_replace));

}