Example #1
0
void read_file_path()
{
	// If 'F' flag was passed
	if(singleFile == TRUE){
		
		FILE *log_fp;
		fprintf(stderr, "reading a log file: %s", filePath);
		
		log_fp = fopen(filePath, "r");
		if(log_fp == NULL) {
				fprintf(stderr, "file open error: %s", filePath);
		}

		read_log(log_fp, filePath);
		fclose(log_fp);
		UBSI_buffer_flush();
		
	}else{ // If 'f' flag was passed
	
		FILE *fp = fopen(filePath, "r");
		FILE *log_fp;
		char tmp[1024];
		char buffer[BUFFER_LENGTH];

		if(fp == NULL) {
				fprintf(stderr, "file open error: %s\n", filePath);
				return;
		}

		while(!feof(fp)) {
				if(fgets(tmp, 1024, fp) == NULL) break;
				fprintf(stderr, "reading a log file: %s", tmp);
				if(tmp[strlen(tmp)-1] == '\n') tmp[strlen(tmp)-1] = '\0';
				
				log_fp = fopen(tmp, "r");
				if(log_fp == NULL) {
						fprintf(stderr, "file open error: %s", tmp);
						continue;
				}

				read_log(log_fp, tmp);
				fclose(log_fp);
		}

		UBSI_buffer_flush();
		fclose(fp);
	}
}
Example #2
0
int     GetConfigRec        (uchar *buf, bool bEraseReqd)
{
    rSysParaHdr *pHdr;
    rAWSysPar   *pInfo;
    int         len = 0x2760;

    pHdr  = (rSysParaHdr*) buf;
    pInfo = (rAWSysPar*) &(buf [20]);

    if (IsA10 (version))
        len = 0x1578;

    read_log (buf, len, FN->ConfigRec);

    *pInfo = DramInfo;

//      save_file ((char *) "Dump1_A10_config", buf, 0x1578);

    pHdr->EraseChipFlag = bEraseReqd;
    if (IsA10 (version))
        return len;

    pInfo->dram_rank_num     = 0xFFFFFFFF;
    pInfo->dram_chip_density = 0xFFFFFFFF;
    pInfo->dram_io_width     = 0xFFFFFFFF;
    pInfo->dram_bus_width    = 0xFFFFFFFF;
    pInfo->dram_size         = 0xFFFFFFFF;

//  if (CB2_mode)
//      buf [0x218] = 0x04;

//  buf [0x218] = RAM_MB_count / 256;   // why did I do this ?

    return len;
}
Example #3
0
int main(int argc, char *argv[]) {
		int max_pid, i;
		char *programName = argv[0];
		int audispdSocketDescriptor = -1, charactersRead, bytesReceived;
		char buffer[BUFFER_LENGTH];
		struct sockaddr_un serverAddress;

		
		putenv("TZ=EST5EDT"); // set timezone
		tzset();

		command_line_option(argc, argv);

		signal(SIGINT, UBSI_sig_handler);
		signal(SIGKILL, UBSI_sig_handler);
		signal(SIGTERM, UBSI_sig_handler);

		max_pid = get_max_pid() + 1;
		max_pid = max_pid*2;
		thread_create_time = (thread_time_t*) UBSI_malloc(sizeof(thread_time_t)*max_pid, 1);
		for(i = 0; i < max_pid; i++) {
				thread_create_time[i].seconds = 0;
				thread_create_time[i].milliseconds = 0;
		}

		if(socketRead) socket_read(programName);
		else if(fileRead) read_file_path();
		else if(dirRead) dir_read();
		else read_log(stdin, "stdin");

		return 0;
}
Example #4
0
int printlog_cgi(HttpState* state)
{
	auto int bytes_written;

	switch(state->substate) {
		case PRTLOG_INIT:
			state->p=&prtlog_header[0];
			state->substate=PRTLOG_HEADER;
         read_log_reset();

			// intentionally no break

		case PRTLOG_HEADER:
			if(*state->p) {
				bytes_written=sock_fastwrite(&state->s,state->p,strlen(state->p));
				if(bytes_written>0)
					state->p+=bytes_written;
			} else {
				state->p=NULL;
				state->offset=0;
				state->substate=PRTLOG_PRTITEM;
			}
			break;

		case PRTLOG_PRTITEM:
			if(state->p==NULL || *state->p=='\0' || *state->p=='\xff') {
         	read_log(state->buffer, 128);

         	if(strlen(state->buffer))
            {
            	//still reading out log contents
				 	state->p=state->buffer;
               state->offset = 0;
				} else {
					state->offset=0;
					state->p=&prtlog_footer[0];
					state->substate=PRTLOG_FOOTER;
				}
				state->offset++;
			} else {
				bytes_written=sock_fastwrite(&state->s,state->p,strlen(state->p));
				if(bytes_written>0) {
					state->p+=bytes_written;
				}
			}
			break;

		case PRTLOG_FOOTER:
			if(*state->p) {
				bytes_written=sock_fastwrite(&state->s,state->p,strlen(state->p));
				if(bytes_written>0)
					state->p+=bytes_written;
			} else
				return 1;			// done

			break;
	}
	return 0;
}
Example #5
0
int main(void){
	int fd;
	init_users();
	numberOfUsers=51;
	printf("%d\n",create_user(5,"HELLBOY"));
	fd=open_log(21,WRITE);
	write_log(fd,"Hello guys");
	close_log(fd);
	fd=open_log(21,READ);
	read_log(fd);
	close_log(fd);
	return 0;
}
 TEST_F(ObPosLogReaderTest, WriteAndReadById){
   int64_t end_id = 0;
   int64_t n_err = 0;
   ASSERT_EQ(OB_SUCCESS, write_log_to_end(log_writer, log_generator, max_num_items));
   for (int64_t i = 2; i < max_num_items; i = end_id)
   {
     if (OB_SUCCESS != (err = read_log(i, end_id)))
     {
       TBSYS_LOG(DEBUG, "read_log(%ld)=>%d", i, err);
       n_err++;
       end_id = i;
     }
   }
   ASSERT_EQ(0, n_err);
 }
Example #7
0
int
main(int argc, char **argv)
{
	int ch;
	int init = 0;
	int size = 0;
	int optf = 0;

	pname = argv[0];

	while ((ch = getopt(argc, argv, "fis:")) != -1)
		switch(ch) {
		case 'i':
			init = 1;
			break;
		case 's':
			size = atol(optarg);
			if (size==0) usage();
			break;
		case 'f':
			optf = 1;
		}

	if ((size>0)&&(init==0)) {
		fprintf(stderr,"%s: WARNING: -s argument ignored without -i.\n",pname);
		size = 0;
	}
	if (argv[optind]==NULL) {
		fprintf(stderr,"%s: ERROR: log_file argument must be specified.\n",pname);
		usage();
	}
	if ((init==1)&&(size==0)) {
		fprintf(stderr,"%s: ERROR: -i argument requires -s.\n",pname);
		usage();
	}
	if ((init==1)&&(optf==1)) {
		fprintf(stderr,"%s: ERROR: flags -f and -i are incompatible.\n",pname);
		usage();
	}

	if (init==1) init_log(argv[optind],size);
	/* if (optf==1) follow_log(artv[optind]); */
	read_log(argv[optind],optf);
		
	return 0;
}
Example #8
0
File: log59.c Project: jleffler/soq
int main(void)
{
    int pipefd[2];
    pid_t pid;
    char szLogtest1[] = "Log Event: Blah blah blah\n";
    char szLogtest2[] = "Log Event: Blah blah 2\n";

    if (pipe(pipefd) != 0)
        exit(1);

    if ((pid = fork()) == -1)
    {
        fprintf(stderr, "Fork error!\n");
        exit(1);
    }
    else if (pid == 0)
    {
        printf("%d: I am child!\n", (int)getpid());
        close(pipefd[1]);     // close the write end of pipe

        char readbuffer[512];
        int nbytes;
        while ((nbytes = read_log(pipefd[0], sizeof(readbuffer), readbuffer)) > 0)
        {
            printf("%d: Logging string: %d [%s]\n", (int)getpid(), nbytes, readbuffer);
        }
        close(pipefd[0]);
        printf("EOF on pipe -exiting\n");
        exit(EXIT_SUCCESS);
    }
    else
    {
        printf("%d: I am parent!\n", (int)getpid());
        close(pipefd[0]);     // close read end of pipe

        write_log(pipefd[1], szLogtest1);
        write_log(pipefd[1], szLogtest2);
        close(pipefd[1]);
        wait_for(pid);
    }

    return 0;
}
 TEST_F(ObPosLogReaderTest, WriteAndReadByLocation){
   int64_t n_err = 0;
   ObLogLocation start_location;
   ObLogLocation end_location;
   start_location.log_id_ = 1;
   ASSERT_EQ(OB_SUCCESS, write_log_to_end(log_writer, log_generator, max_num_items));
   for (; start_location.log_id_ < max_num_items; )
   {
     if (OB_SUCCESS != (err = read_log(start_location, end_location)))
     {
       TBSYS_LOG(DEBUG, "read_log(%ld)=>%d", start_location.log_id_, err);
       n_err++;
     }
     else
     {
       start_location = end_location;
     }
   }
   ASSERT_EQ(0, n_err);
 }
Example #10
0
/** 
 *  http_handler - http handler
 */ 
void http_handler(struct evhttp_request *req, void *arg)
{
    time_t timep;
    struct tm *m;
    struct stat info;
  
    struct evbuffer *buf;
    buf = evbuffer_new();
      
    // 分析URL参数
    char *decode_uri = strdup((char*) evhttp_request_uri(req));
	decode_uri = evhttp_decode_uri(decode_uri);
	if (strcmp(decode_uri, "/") == 0) decode_uri = "/index.html";
    sprintf(http_req_line.request_uri, "%s", decode_uri);

    // 返回给浏览器的头信息
    evhttp_add_header(req->output_headers, "Server", "logadmin");
    evhttp_add_header(req->output_headers, "Connection", "close");
  
    // 取得请求时间
    time(&timep);
    m = localtime(&timep);
    sprintf(http_req_line.request_time, "%4d-%02d-%02d %02d:%02d:%02d", (1900+m->tm_year), (1+m->tm_mon), m->tm_mday, m->tm_hour, m->tm_min, m->tm_sec);
  
    // 获取ACTION的值
	struct evkeyvalq params;
	evhttp_parse_query(decode_uri, &params);
    char *action = (char*)evhttp_find_header(&params, "action");
  
    // 处理不同的ACTION
	if (action) {
		char *tmp = "";
		evhttp_add_header(req->output_headers, "Content-Type", "text/html; charset=UTF-8");
		if (strcmp(action, "loginfo") == 0) {
			char *loghost = (char*)evhttp_find_header(&params, "loghost");
			char *logport = (char*)evhttp_find_header(&params, "logport");
			char *logname = (char*)evhttp_find_header(&params, "logname");
			char *pagenum = (char*)evhttp_find_header(&params, "pagenum");
			int pnum = pagenum ? atoi(pagenum) : 1;
			int port = logport ? atoi(logport) : 8706;
			if (logname) {
				int psize = 20;
				char *logreg = (char*)evhttp_find_header(&params, "logreg");
				if(!logreg || !strlen(logreg)){
					logreg = ".*";
				}
				char *cmd = joinstr("grep '%s' %s -c && grep '%s' %s | tail -n +%d | head -n %d", logreg, logname, logreg, logname, (pnum - 1) * psize, psize);
				if (!loghost || !strlen(loghost)) {
					tmp = exec_cmd(cmd);
				} else {
					sock_cmd(loghost, port, cmd, (char*)&tmp, MEM_SIZE);
				}
			}
			evbuffer_add_printf(buf, "%s", tmp);
			evhttp_send_reply(req, HTTP_OK, "OK", buf);
		} else if(strcmp(action, "loglist") == 0) {
			char *loghost = (char*)evhttp_find_header(&params, "loghost");
			char *logport = (char*)evhttp_find_header(&params, "logport");
			char *dirname = (char*)evhttp_find_header(&params, "dirname");
			int port = logport ? atoi(logport) : 8706;
			if (dirname) {
				char *cmd = joinstr("ls -lF %s | awk '{print $9}'", dirname);
				if (!loghost || !strlen(loghost)) {
					tmp = exec_cmd(cmd);
				} else {
					sock_cmd(loghost, port, cmd, (char*)&tmp, MEM_SIZE);
				}
			}
			evbuffer_add_printf(buf, "%s", tmp);
			evhttp_send_reply(req, HTTP_OK, "OK", buf);
		} else if(strcmp(action, "logconf") == 0) {
#ifndef __WIN32
			GKeyFile* config = g_key_file_new();
			GKeyFileFlags flags = G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS;
			if (g_key_file_load_from_file(config, "./conf/logadmin.conf", flags, NULL)) {
				int i;
				gsize length;
				gchar** groups = g_key_file_get_groups(config, &length);
				for (i = 0; i < (int)length; i++) {
					gchar* host = g_key_file_get_string(config, groups[i], "host", NULL);
					gchar* path = g_key_file_get_string(config, groups[i], "path", NULL);
					gchar* port = g_key_file_get_string(config, groups[i], "port", NULL);
					if(!port || !strlen(port)) port = "8706";
					if (host && path) tmp = joinstr("%s%s:%s;%s\n", tmp, host, port, path);
				}
			}
			g_key_file_free(config);
#endif
			evbuffer_add_printf(buf, "%s", tmp);
			evhttp_send_reply(req, HTTP_OK, "OK", buf);
		} else {
			evbuffer_add_printf(buf, "<html><head><title>870 Error Action</title></head><body><h1 align=\"center\">870 Error Action</h1></body></html>");
			evhttp_send_reply(req, 870, "Error Action", buf);
		}
		evbuffer_free(buf);
		return;
	}
  
    // 获取请求的服务器文件路径
    char *dir_root = getcwd(NULL, 0);
    char *real_path = joinstr("%s/%s%s", dir_root, DOCUMENT_ROOT, http_req_line.request_uri);

    if (stat(real_path,&info) == -1) {
        evhttp_add_header(req->output_headers, "Content-Type", "text/html; charset=UTF-8");
        if (errno == ENOENT)
        {
			evbuffer_add_printf(buf, "<html><head><title>404 Not Found</title></head><body><h1 align=\"center\">404 Not Found</h1></body></html>");
			evhttp_send_reply(req, 404, "Not Found", buf);
        }  
        else if(access(real_path,R_OK) < 0)
        {
			evbuffer_add_printf(buf, "<html><head><title>403 Not Found</title></head><body><h1 align=\"center\">403 Forbidden</h1></body></html>");
			evhttp_send_reply(req, 403, "Forbidden", buf);
        }  
        else  
        {
			evbuffer_add_printf(buf, "<html><head><title>500 Server Error</title></head><body><h1 align=\"center\">500 Server Error</h1></body></html>");
			evhttp_send_reply(req, 500, "Server Error", buf);
        }
    } else if(S_ISREG(info.st_mode)) {
        // 设置HEADER头并输出内容到浏览器
        evhttp_add_header(req->output_headers, "Content-Type", joinstr("%s; charset=UTF-8", mime_type(real_path)));
        evbuffer_add_printf(buf, "%s", read_log(real_path));
        evhttp_send_reply(req, HTTP_OK, "OK", buf);
    }

    // 内存释放
    evbuffer_free(buf);
    free(dir_root);
}
Example #11
0
int
main(int argc, char *argv[])
{
	bool log_read = false;
	int select_cluster = -1, select_proc = -1;

	myDistro->Init( argc, argv );
	if (argc == 1) {
		fprintf(stderr, usage, argv[0]);
		exit(1);
	}

	for (int i=1; i < argc; i++) {
		if (argv[i][0] == '-') {
			switch (argv[i][1]) {
			case 'a':
				select_cluster = select_proc = -1;
				evict_only = false;
				break;
			case 'j': {
				i++;
				if (1 != sscanf(argv[i], "%d", &select_cluster))
					select_cluster = -1;
				char *proc_str = strchr(argv[i], '.');
				if (proc_str) {
					if (1 != sscanf(proc_str+1, "%d", &select_proc))
						select_proc = -1;
				}
				break;
			}
			case 't': {
				totals_only = true;
				break;
			}
			case 'd': {
				debug_mode = true;
				break;
			}
			case 'e': {
				evict_only = true;
				break;
			}
			case 'r': {
				raw_data = true;
				break;
			}
			case 'h': {
				if (argv[i][2] == 'o') {
					avoid_dns = false;
				} else {
					fprintf(stderr, usage, argv[0]);
					exit(0);
				}
				break;
			}
			default:
				fprintf(stderr, usage, argv[0]);
				exit(1);
			}
		} else {
			if (access(argv[i], R_OK) < 0) {
				fprintf(stderr, "Can't access file: %s (errno=%d)\n", argv[i],
						errno);
			} else {
				read_log(argv[i], select_cluster, select_proc);
				log_read = true;
			}
		}
	}

	if (log_read && !raw_data) {
		printf("\n");
		display_stats();
	}

	return 0;
}
Example #12
0
int printlog_cgi(HttpState *state)
{
   auto int bytes_written;

   switch (state->substate)
   {
   case PRTLOG_INIT:
      // Temporarily cast const away since the p member in HttpState is a
      // general purpose pointer
      state->p = (char *) &prtlog_header[0];
      state->substate = PRTLOG_HEADER;
      read_log_reset();

      // intentionally no break

   case PRTLOG_HEADER:
      if (*state->p)
      {
         bytes_written = sock_fastwrite(&state->s, state->p, strlen(state->p));
         if (bytes_written > 0)
         {
            state->p += bytes_written;
         }
      }
      else
      {
         state->p = NULL;
         state->offset = 0;
         state->substate = PRTLOG_PRTITEM;
      }
      break;

   case PRTLOG_PRTITEM:
      if (state->p == NULL || *state->p == '\0' || *state->p == '\xff')
      {
         read_log(state->buffer, 128);
         if (strlen(state->buffer))
         {
            //still reading out log contents
            state->p = state->buffer;
            state->offset = 0;
         }
         else
         {
            state->offset = 0;
            // Temporarily cast const away since the p member in HttpState is
            // a general purpose pointer
            state->p = (char *) &prtlog_footer[0];
            state->substate = PRTLOG_FOOTER;
         }
         ++state->offset;
      }
      else
      {
         bytes_written = sock_fastwrite(&state->s, state->p, strlen(state->p));
         if (bytes_written > 0)
         {
            state->p += bytes_written;
         }
      }
      break;

   case PRTLOG_FOOTER:
      if (*state->p)
      {
         bytes_written = sock_fastwrite(&state->s, state->p, strlen(state->p));
         if (bytes_written > 0)
         {
            state->p += bytes_written;
         }
      }
      else
      {
         return 1;   // done
      }
      break;
   }
   return 0;
}
Example #13
0
int main(int argc, char **argv)
{
	extern char *optarg;
	extern int optind;
	int c, error = 0, ret;
	struct hist_data h;
	int retlog;

	/* Allocate heap for download request	
	 * struct request stores all the information that might be
	 * of interest
	 */
	req = (struct request *)calloc(1, sizeof(struct request));

	/* Only some signals will be emitted	*/
	sigemptyset(&signal_set);
	sigaddset(&signal_set, SIGINT);
	sigaddset(&signal_set, SIGALRM);

	/* Block out all signals	*/
	pthread_sigmask(SIG_BLOCK, &signal_set, NULL);

	/* Create a thread for hadling signals	*/
	if ((ret = pthread_create(&hthread, NULL, signal_waiter, NULL)) != 0) {
		fprintf(stderr, "main: cannot create signal_waiter thread: %s, exiting...\n", strerror(errno));
		exit(-1);
	}

	while (!error && (c = getopt(argc,argv,"p:l:n:hfv")) != -1) {
		switch(c) {
			case 'p':
				req->port = atoi(optarg);
				break;
			case 'f':
				fsuggested = 1;
				break;
			case 'l':
				strncpy(req->lfile, optarg, MAXBUFSIZ);
				break;
			case 'n':
				if ((nthreads = atoi(optarg)) > MAXTHREADS) {
					Log("Error: Maximum # of threads allowed is %d\n", MAXTHREADS);
					nthreads = 0;
				}
				break;
			case 'h':
				printf("%s\n", PROGVERSION);
				usage();
				exit(0);
				break;
			case 'v':
				printf("%s\nby Murat BALABAN <*****@*****.**>\n", PROGVERSION);
				exit(0);
				break;
			default:
				error = 1;
				usage();
				exit(1);
				break;
		}
	}

	if (error) {
		usage();
		exit(1);
	}

	if (fsuggested == 1 && nthreads == 0) {
		fprintf(stderr, "\nERROR: -f and -n should be used together!, exiting...\n\n");
		usage();
		exit(1);
	}

	if (argc == 2) 		/* If only url is supplied...	*/
		fullurl = strdup(argv[1]);
	else
	if (optind < argc)
		if (argc > 2)
			fullurl = strdup(argv[optind]);
		else {
			usage();
			exit(1);
		}
	else
	if (optind == argc) {
		usage();
		exit(1);
	}
	
	parse_url(fullurl, req);

	/* If a log file for a previous try has been found, read it and
	 * resume the download job (resume_get), otherwise, start with
	 * a clean job (get) 
	 *
	 * Logfile is of the pattern: aget-$file_name.log
	 */
	if ((retlog = read_log(&h)) != -1)
		resume_get(&h);
	else
		get(req);

	return 0;
}
Example #14
0
int main(int argc, char **argv){
	char buffer[BUFFER_SIZE];
	int numArgs;
	char *arg_vector[VECTOR_SIZE];
	time_t starttime;
	
	int child_pid;
	pthread_t monitor_thread;
	pthread_t writer_thread;
	lst = lst_new();
	writing_queue = new_queue();

	/* Initialize synchronization objects */
	pthread_mutex_init_(&mutex, NULL);
	pthread_cond_init_(&write_cond, 0);
	pthread_cond_init_(&max_par, NULL);
	pthread_cond_init_(&new_child, NULL);

	if ((log_fd = fopen("./log.txt", "a+")) == NULL){
		perror("[ERROR] opening log file");
		exit(EXIT_FAILURE);
	}
	read_log(); /* assign total time and iteration values for this execution */
	pthread_create_(&monitor_thread, NULL, (void *)&monitor, NULL); /* Create Monitor Thread */  
	pthread_create_(&writer_thread, NULL, (void *)&writer, NULL); /* Create Writer Thread */
 
	while (1) {
		numArgs = readLineArguments(arg_vector, VECTOR_SIZE, buffer, BUFFER_SIZE);
		if (numArgs <= 0)continue;

		if (strcmp(arg_vector[0], EXIT_COMMAND) == 0 ) {

			/* signal exit command */
			exit_command = 1;

			/* wait for monitor thread to end */
			pthread_cond_signal_(&new_child); /* must signal to catch exit flag */
			pthread_join_(monitor_thread, NULL);
			pthread_join_(writer_thread, NULL);

			/* print all the elements in the list */
			lst_print(lst);
			
			/* terminate sync objects */
			pthread_mutex_destroy_(&mutex);
			pthread_cond_destroy_(&write_cond);
			pthread_cond_destroy_(&max_par);
			pthread_cond_destroy_(&new_child);
			fclose(log_fd);
			lst_destroy(lst);
			exit(EXIT_SUCCESS);
		}

		/* while there are child process slots available launch new child process,
		* else wait here */
		pthread_mutex_lock_(&mutex);
		while (child_count >= MAXPAR) pthread_cond_wait_(&max_par, &mutex);
		pthread_mutex_unlock_(&mutex);

		child_pid = fork();
		if (child_pid < 0){ /* test for error in fork */
			perror("[ERROR] forking process");
			continue;
		}
		if (child_pid == 0){ /* execute on child */
			if (execv(arg_vector[0], arg_vector) == -1) {
			perror("[ERROR] executing program.");
			exit(EXIT_FAILURE);
			}
		}
		else { /* execute on parent */
			/* Main thread
			 *
			 * Child processes are inserted into the process list saving their pid
			 * and their start time.
			 * Child counter is incremented.
			 * The condition variable waiting for a new child process is signaled.
 			 */
			time(&starttime); /* get start time of child process */
			pthread_mutex_lock_(&mutex);
			insert_new_process(lst, child_pid, starttime);
			child_count++;
			pthread_cond_signal_(&new_child);
			pthread_mutex_unlock_(&mutex);
		}
	}
}
Example #15
0
int main(int argc, char *argv[])
{
	int n,
		show_days = 0,
		but_stat  = 0,
		microtm   = 0,
		running   = 0,
		force     = 0;
	time_t
		last_time = 0;
	char
		*geometry = NULL,
		*xdisplay = NULL;
	static int signals[] =
		{SIGALRM, SIGHUP, SIGINT, SIGPIPE, SIGTERM, SIGUSR1, SIGUSR2, 0};
	XEvent Event;

	assert(sizeof(char) == 1);

	umask(077);
	do_opts(argc, argv, &show_days, &xdisplay, &geometry, &force);

	path_len = strlen(getenv("HOME")) + strlen("/.wmwork/worklog") + 1;
	if ((dirName = malloc(path_len)) == NULL || (logname = malloc(path_len)) == NULL || (lockname = malloc(path_len)) == NULL) {
		fprintf(stderr, "%s: cannot allocate memory for path variable\n", PACKAGE_NAME);
		fprintf(stderr, "%s: %s\n", PACKAGE_NAME, strerror(errno));
		exit(1);
	}
	snprintf(dirName,  path_len, "%s/.wmwork", getenv("HOME"));
	snprintf(logname,  path_len, "%s/worklog", dirName);
	snprintf(lockname, path_len, "%s/.#LOCK",  dirName);
	if (chdir(dirName) < 0) {
		if (errno == ENOENT) {
			if (mkdir(dirName, 0777)) {
				fprintf(stderr, "%s: cannot mkdir '%s'\n", PACKAGE_NAME, dirName);
				fprintf(stderr, "%s: %s\n", PACKAGE_NAME, strerror(errno));
				exit(1);
			}
			compat();
		} else {
			fprintf(stderr, "%s: cannot chdir into '%s'\n", PACKAGE_NAME, dirName);
			fprintf(stderr, "%s: %s\n", PACKAGE_NAME, strerror(errno));
			exit(1);
		}
	}

	for (n = 0; signals[n]; n++) {
		if (signal(signals[n], handler) == SIG_ERR) {
			fprintf(stderr, "%s: cannot set handler for signal %d\n", PACKAGE_NAME, signals[n]);
			fprintf(stderr, "%s: %s\n", PACKAGE_NAME, strerror(errno));
		}
	}

	make_lock(force);
	atexit(at_exit);
	read_log();
	current = first;

	initXwindow(xdisplay);
	createXBMfromXPM(wmwork_mask_bits, wmwork_master_xpm, 64, 64);
	openXwindow(argc, argv, wmwork_master_xpm, wmwork_mask_bits, 64, 64, geometry, NULL);
	AddMouseRegion(BUT_START,  5, 48, 22, 58);
	AddMouseRegion(BUT_PAUSE, 23, 48, 40, 58);
	AddMouseRegion(BUT_STOP,  41, 48, 58, 58);
	AddMouseRegion(BUT_PREV,   5, 33, 16, 43);
	AddMouseRegion(BUT_NEXT,  47, 33, 58, 43);
	drawTime(current->time, sess_time, microtm, show_days, running);
	drawProject(current->name);

	while (1) {
		last_time = now.tv_sec;
		gettimeofday(&now, &tz);
		if (running) {
			current->time += now.tv_sec - last_time;
			sess_time     += now.tv_sec - last_time;
			microtm        = now.tv_usec;
			drawTime(current->time, sess_time, microtm, show_days, running);
			RedrawWindow();
		}
		while (XPending(display)) {
			XNextEvent(display, &Event);
			switch (Event.type) {
			case Expose:
				RedrawWindow();
				break;
			case DestroyNotify:
				XCloseDisplay(display);
				exit(0);
			case ButtonPress:
				n = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
				switch (n) {
				case BUT_START:
				case BUT_PAUSE:
				case BUT_STOP:
				case BUT_PREV:
				case BUT_NEXT:
					ButtonDown(n);
					break;
				}
				but_stat = n;
				RedrawWindow();
				break;
			case ButtonRelease:
				n = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
				switch (but_stat) {
				case BUT_START:
				case BUT_PAUSE:
				case BUT_STOP:
				case BUT_PREV:
				case BUT_NEXT:
					ButtonUp(but_stat);
					break;
				}
				if (but_stat && n == but_stat) {
					switch (but_stat) {
					case BUT_START:
						running = 1;
						break;
					case BUT_PAUSE:
						running = 0;
						break;
					case BUT_STOP:
						write_log();
						write_record();
						running   = 0;
						sess_time = 0;
						break;
					case BUT_PREV:
						if (!running && sess_time == 0)
							current = current->prev;
						break;
					case BUT_NEXT:
						if (!running && sess_time == 0)
							current = current->next;
						break;
					}
					drawTime(current->time, sess_time, microtm, show_days, running);
					drawProject(current->name);
				}
				RedrawWindow();
				but_stat = 0;
				break;
			}
		}
		usleep(50000L);
		if (do_exit)
			exit(0);
	}
}
int main(int argc, char *argv[])
{
	FILE *infp, *outfp;
	int type, n, i;
	char *p;
	struct node_mcc *mcc;
	struct node_mnc *mnc;
	struct node_lac *lac;
	struct node_cell *cell;
	struct node_meas *meas;

	log_init(&log_info, NULL);
	stderr_target = log_target_create_stderr();
	log_add_target(stderr_target);
	log_set_all_filter(stderr_target, 1);
	log_parse_category_mask(stderr_target, "Dxxx");
	log_set_log_level(stderr_target, LOGL_INFO);

	if (argc <= 2) {
usage:
		fprintf(stderr, "Usage: %s <file.log> <file.kml> "
			"[lines] [debug]\n", argv[0]);
		fprintf(stderr, "lines: Add lines between cell and "
			"Measurement point\n");
		fprintf(stderr, "debug: Add debugging of location algorithm.\n"
			);
		return 0;
	}

	for (i = 3; i < argc; i++) {
		if (!strcmp(argv[i], "lines"))
			log_lines = 1;
		else if (!strcmp(argv[i], "debug"))
			log_debug = 1;
		else goto usage;
	}

	infp = fopen(argv[1], "r");
	if (!infp) {
		fprintf(stderr, "Failed to open '%s' for reading\n", argv[1]);
		return -EIO;
	}

	while ((type = read_log(infp))) {
		switch (type) {
		case LOG_TYPE_SYSINFO:
			add_sysinfo();
			break;
		case LOG_TYPE_POWER:
			add_power();
			break;
		}
	}

	fclose(infp);

	if (!strcmp(argv[2], "-"))
		outfp = stdout;
	else
		outfp = fopen(argv[2], "w");
	if (!outfp) {
		fprintf(stderr, "Failed to open '%s' for writing\n", argv[2]);
		return -EIO;
	}

	/* document name */
	p = argv[2];
	while (strchr(p, '/'))
		p = strchr(p, '/') + 1;

	kml_header(outfp, p);
	mcc = node_mcc_first;
	while (mcc) {
	  printf("MCC: %02x\n", mcc->mcc);
	 /* folder open */
	  fprintf(outfp, "\t<Folder>\n");
	  fprintf(outfp, "\t\t<name>MCC %s (%s)</name>\n",
		gsm_print_mcc(mcc->mcc), gsm_get_mcc(mcc->mcc));
	  fprintf(outfp, "\t\t<open>0</open>\n");
	  mnc = mcc->mnc;
	  while (mnc) {
	    printf(" MNC: %02x\n", mnc->mnc);
	    /* folder open */
	    fprintf(outfp, "\t\t<Folder>\n");
	    fprintf(outfp, "\t\t\t<name>MNC %s (%s)</name>\n",
	    	gsm_print_mnc(mnc->mnc), gsm_get_mnc(mcc->mcc, mnc->mnc));
	    fprintf(outfp, "\t\t\t<open>0</open>\n");
	    lac = mnc->lac;
	    while (lac) {
	      printf("  LAC: %04x\n", lac->lac);
	      /* folder open */
	      fprintf(outfp, "\t\t\t<Folder>\n");
	      fprintf(outfp, "\t\t\t\t<name>LAC %04x</name>\n", lac->lac);
	      fprintf(outfp, "\t\t\t\t<open>0</open>\n");
	      cell = lac->cell;
	      while (cell) {
		printf("   CELL: %04x\n", cell->cellid);
		fprintf(outfp, "\t\t\t\t<Folder>\n");
		fprintf(outfp, "\t\t\t\t\t<name>CELL-ID %04x</name>\n", cell->cellid);
		fprintf(outfp, "\t\t\t\t\t<open>0</open>\n");
		meas = cell->meas;
		n = 0;
		while (meas) {
			if (meas->ta_valid)
				printf("    TA: %d\n", meas->ta);
			if (meas->gps_valid)
				kml_meas(outfp, meas, ++n, mcc->mcc, mnc->mnc,
					lac->lac, cell->cellid);
			meas = meas->next;
		}
		kml_cell(outfp, cell);
		/* folder close */
		fprintf(outfp, "\t\t\t\t</Folder>\n");
		cell = cell->next;
	      }
	      /* folder close */
	      fprintf(outfp, "\t\t\t</Folder>\n");
	      lac = lac->next;
	    }
	    /* folder close */
	    fprintf(outfp, "\t\t</Folder>\n");
	    mnc = mnc->next;
	  }
	  /* folder close */
	  fprintf(outfp, "\t</Folder>\n");
	  mcc = mcc->next;
	}
#if 0
	FIXME: power
	/* folder open */
	fprintf(outfp, "\t<Folder>\n");
	fprintf(outfp, "\t\t<name>Power</name>\n");
	fprintf(outfp, "\t\t<open>0</open>\n");
	power = node_power_first;
	n = 0;
	while (power) {
		/* folder open */
		fprintf(outfp, "\t\t<Folder>\n");
		fprintf(outfp, "\t\t\t<name>Power %d</name>\n", ++n);
		fprintf(outfp, "\t\t\t<open>0</open>\n");
		/* folder close */
		fprintf(outfp, "\t\t</Folder>\n");
		power = power->next;
	}
	/* folder close */
	fprintf(outfp, "\t</Folder>\n");
#endif
	kml_footer(outfp);

	fclose(outfp);

	return 0;
}
Example #17
0
int main(int argc, char *argv[])
{		
	// Variables	
	// Default CSS
	char CSSFILE[12]="style.css";

	// Pointers to filenames
	char *infofilename = INFO;
	char *logfilename = LOG;
	
	// Handle arguments
	int opt;
	while ((opt=getopt_long(argc, argv, "dvhm", main_options, NULL)) != EOF)
	{
		switch (opt)
		{
		case 'h':
			help();
			exit(0);
		case 'd':
			debug();
			exit(0);
		case 'v':
			printf("%s (v%s) by MS3FGX\n", APPNAME, VERSION);
			exit(0);
			break;
		case 'm':
			strcpy(CSSFILE, "mobile.css");
			mobile = 1;
			break;
		default:
			printf("Unknown option.\n");
			exit(0);
		}
	}
	
	// Bail out if we are root, except on WRT
	#ifndef OPENWRT
	if(getuid() == 0)
	{
		syslog(LOG_ERR,"CGI module refusing to run as root!");
		printf("Server attempting to run CGI module as root, bailing out!\n");
		printf("Check your web server configuration and try again.\n");
		exit(1);
	}
	#endif

	// Read in environment variable
	// Comment this to fix compiler warning until ready to implement
	//char* env_string;
	//env_string=getenv("QUERY_STRING");

	// Print HTML head
	print_header(CSSFILE);
	//print_html(CSSFILE);
	
	// Start container div
	if (!mobile)
		puts("<div id=\"container\">\n");

	// Open files
	if ((infofile = fopen(infofilename, "r")) == NULL)
	{
		syslog(LOG_ERR,"Error while opening %s!",infofilename);
		puts("<div id=\"content\">");
		printf("Error while opening %s!\n",infofilename);
		puts("</body></html>");
		exit(1);
	}
	
	if ((logfile = fopen(logfilename, "r")) == NULL)
	{
		syslog(LOG_ERR,"Error while opening %s!",logfilename);
		puts("<div id=\"content\">");
		printf("Error while opening %s!\n",logfilename);
		puts("</body></html>");
		exit(1);
	}
	
	// Draw sidebar\topbar
	read_log();
	if (!mobile)
		SideBar();
	else
		TopBar();
	
	// Content window
	puts("<div id=\"content\">");
	
	if (device_index > 0)
	{
		// Print results
		setup_table();
		print_devices();
		puts("</table>\n");
	}
	
	// Close content, body, and HTML
	puts("</div></body></html>");
	
	// Close files and exit
	shut_down();
	return 0;
}
Example #18
0
int     install_fes_1_1 (libusb_device_handle *handle, uchar *buf)
{
    rAWSysPar       *pDI;
    int             len = 0x200;

    ShowURB (63);

    PutNulls (buf, 512);
    pDI = (rAWSysPar*) buf;
    pDI->unk_6 = 0x007C4AC1;                            // UART 0 TX pin specs
    if (IsA10 (version))                                // A10 defaults
      {
        pDI->unk_0           = 0x02000000;                  // chip
        pDI->unk_1           = 0x02000000;                  // pid
        pDI->unk_2           = 0x02000100;                  // sid
        pDI->unk_3           = 0x80;                        // bid
//      pDI->dram_baseaddr   = 0x40000000;                  // from Ronald T.
//      pDI->dram_clk        = 480;
//      pDI->dram_type       = 3;
//      pDI->dram_rank_num   = 1;
//      pDI->dram_chip_density = 4096;
//      pDI->dram_io_width   = 16;
//      pDI->dram_bus_width  = 32;
//      pDI->dram_cas        = 6;
//      pDI->dram_zq         = 0x7b;
//      pDI->dram_odt_en     = 0;
//      pDI->dram_size       = 1024;
//      pDI->dram_tpr0       = 0x30926692;
//      pDI->dram_tpr1       = 0x1090;
//      pDI->dram_tpr2       = 0x1a0c8;
//      pDI->dram_tpr3       = 0x0;
        pDI->dram_tpr4       = 0x40000000;                  // from USB trace.
        pDI->dram_tpr5       = 480;                         // all values here
        pDI->dram_emr1       = 3;                           // are 60 bytes after
        pDI->dram_emr2       = 1;                           // expected location.
        pDI->dram_emr3       = 4096;
        pDI->dram_spare [0]  = 16;
        pDI->dram_spare [1]  = 32;
        pDI->dram_spare [2]  = 6;
        pDI->dram_spare [3]  = 0x7B;
        pDI->dram_spare [4]  = 0;
        pDI->dram_spare [5]  = 1024;
        pDI->dram_spare [6]  = 0x30926692;
        pDI->dram_spare [7]  = 0x1090;
        pDI->dram_spare [8]  = 0x01A0C8;
        pDI->dram_spare [9]  = 0;
//      read_log (buf, 0xB4, FN->DRAM_specs);              // DRAM access specs
        len = 0xB4;
      }

    if (IsA20 (version))                                // A20 defaults
      {
        pDI->dram_baseaddr   = 0x40000000;                  // from CT script.fex
        pDI->dram_clk        = 432;
        pDI->dram_type       = 3;
        pDI->dram_rank_num   = 0xFFFFFFFF;
        pDI->dram_chip_density = 0xFFFFFFFF;
        pDI->dram_io_width   = 0xFFFFFFFF;
        pDI->dram_bus_width  = 0xFFFFFFFF;
        pDI->dram_cas        = 9;
        pDI->dram_zq         = 0x7f;
        pDI->dram_odt_en     = 0;
        pDI->dram_size       = 0xFFFFFFFF;
        pDI->dram_tpr0       = 0x42d899b7;
        pDI->dram_tpr1       = 0xa090;
        pDI->dram_tpr2       = 0x22a00;
        pDI->dram_tpr3       = 0x0;
        pDI->dram_tpr4       = 0x1;
        pDI->dram_tpr5       = 0x0;
        pDI->dram_emr1       = 0x4;
        pDI->dram_emr2       = 0x10;
        pDI->dram_emr3       = 0x0;
//      read_log (buf, 0x200, FN->DRAM_specs);               // DRAM access specs
        len = 0x200;
      }      

    if (IsH3 (version))                                 // H3 defaults
      {
        pDI->dram_baseaddr   = 0x40000000;                  // from H3 script.fex
//      pDI->dram_clk        = 672;
        pDI->dram_clk        = 480;
        pDI->dram_type       = 3;
        pDI->dram_zq         = 0x3b3bfb;
        pDI->dram_odt_en     = 0x1;
//      pDI->dram_para1      = 0x10E40000;
//      pDI->dram_para2      = 0x0000;
//      pDI->dram_mr0        = 0x1840;
        pDI->dram_emr1       = 0x40;
        pDI->dram_emr2       = 0x18;
        pDI->dram_emr3       = 0x2;
        pDI->dram_tpr0       = 0x0048A192;
        pDI->dram_tpr1       = 0x01C2418D;
        pDI->dram_tpr2       = 0x00076051;
        pDI->dram_tpr3       = 0;
        pDI->dram_tpr4       = 0;
        pDI->dram_tpr5       = 0;
//      pDI->dram_tpr6       = 100;
//      pDI->dram_tpr7       = 0;
//      pDI->dram_tpr8       = 0;
//      pDI->dram_tpr9       = 0;
//      pDI->dram_tpr10      = 0;
//      pDI->dram_tpr11      = 0x6aaa0000;
//      pDI->dram_tpr12      = 0x7979;
//      pDI->dram_tpr13      = 0x800800;
      }

    aw_fel_write (handle, 0x7010, buf, len);

    ShowURB (72);
    PutNulls (buf, 16);                                 // clear error log
    aw_fel_write (handle, 0x7210, buf, 0x10);

    ShowURB (77);

#ifdef OLD_EXTRAS
//          Load buffer as per URB 81 (0xae0 = 2784) FES_1-1 with nulls after.
//          We do lots of sanity checks here (relic from testing).
    PutNulls (buf, 65536);
    read_log (buf, 0x0ae0, (char*) "pt1_000081");       // data from log

    FILE *fin;

    if (NULL == (fin = fopen (FN->fes_1_1, "rb")))
      {
        perror ("Failed to open file to send: ");
        exit (1);
      }

    fread (buf + 2784, 1, 2784, fin);                   // data from file
    fclose (fin);

    if (memcmp (buf, buf + 2784, 2784))                 // shouldn't happen
      {
        printf ("Dump / fes_1-1 file mismatch\n");
        save_file ((char *) "Dump1_000077", buf, 5568);
        PerhapsQuit ();
      }
#endif

    if (IsH3 (version))
        return 0;

    aw_fel_send_file (handle, 0x7220, FN->fes_1_1, 2784, 2784);

#ifdef OLD_EXTRAS
    aw_fel_read (handle, 0x7220, buf + 2784, 2784);     // sanity test
    if (memcmp (buf, buf + 2784, 2784))
      {
        printf ("Readback mismatch of fes_1-1\n");
        save_file ((char *) "Dump1_000081", buf + 2784, 2784);
        PerhapsQuit ();
      }
#endif

    ShowURB (87);
    aw_fel_execute (handle, 0x7220);

    usleep (500000);    // need this to avoid error on next USB I/O

    ShowURB (96);
    aw_fel_read (handle, 0x7210, buf, 256);             // expect 'DRAM' then nulls

    if (memcmp (buf, "DRAM\x00\x00\x00\x00", 8))
      {
        perror ("Compare to DRAM lit failed");
        hexdump (buf, 0, 256);
        save_file ((char *) "Dump1_000096", buf, 256);
        PerhapsQuit ();
      }

    return 0;
}
Example #19
0
int main(int argc, char **argv)
{
	int c, error = 0;
	struct hist_data h;
	int retlog;
	char tmp[MAXBUFSIZ];
	char *fullurl;
	extern char *optarg;
	extern int optind;
	sigset_t set;

	main_tid = pthread_self();
	/* Allocate heap for download request	
	 * struct request stores all the information that might be
	 * of interest
	 */
	req = (struct request *)calloc(1, sizeof(struct request));

	/* This is required because if download is aborted before
	 * this is initialized, problems will occur
	 */
	wthread = NULL;

	/* except from signal handler thread, 
	 * no other thread is receiving signals!
	 * No signals are caught here since we need to save download job only
	 * after wthread structures are initialized.
	 * TODO:: We need to create helper thread as soon as head request is over
	 * since the user might wish to stop downloading as soon as he sees the
	 * content length.
	 */
	sigfillset(&set);
	pthread_sigmask(SIG_BLOCK, &set, NULL);

	/* Safe to exit before download starts.
	 * This is set back to DEFERRED before creating helper thread because
	 * we want this to exit only at certain safe points specified using
	 * pthread_testcancel().
	 * Helper thread is started just before creating worker threads and after
	 * wthread structures are initialized. Only after this point do we need to
	 * save download job if an interrupt comes - not before. Helper thread exists
	 * only to catch SIGINT and to save download job. It doesn't make sense to
	 * start it before wthread structures are initialized!
	 */
	pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);


	/* Read the RC file if exist	*/
	readrc();


	/* If set in rc file	*/
	if (preferredthread != -1)
		nthreads = preferredthread;

	while (!error && (c = getopt(argc,argv,"p:l:n:hfv")) != -1) {
		switch(c) {
			case 'p':
				req->port = atoi(optarg);
				break;
			case 'l':
				strncpy(req->lfile, optarg, MAXBUFSIZ -1);
				break;
			case 'n':
				fsuggested = 1;
				if ((nthreads = atoi(optarg)) > MAXTHREADS) {
					Log("Error: Maximum # of threads allowed is %d\n", MAXTHREADS);
					exit(1);
				}
				break;
			case 'h':
				printf("%s\n", PROGVERSION);
				usage();
				exit(0);
				break;
			case 'v':
				printf("%s\nby Murat BALABAN <*****@*****.**>\n", PROGVERSION);
				exit(0);
				break;
			default:
				error = 1;
				usage();
				exit(1);
				break;
		}
	}

	if (error) {
		usage();
		exit(1);
	}

	if (fsuggested == 1 && nthreads == 0) {
		fprintf(stderr, "ERROR: -f and -n should be used together!, exiting...\n");
		usage();
		exit(1);
	}

	if (argc == 2) 		/* If only url is supplied... */
		fullurl = strdup(argv[1]);
	else
	if (optind < argc)
		if (argc > 2)
			fullurl = strdup(argv[optind]);
		else {
			usage();
			exit(1);
		}
	else
	if (optind == argc) {
		usage();
		exit(1);
	}

	parse_url(fullurl, req);


	if(strlen(req->lfile) == 0)
		strncpy(req->lfile, req->file, MAXBUFSIZ - 2);

	getcwd(tmp, MAXBUFSIZ -2);
	strncpy(tmp+strlen(tmp), "/", MAXBUFSIZ - strlen(tmp) - 2);
	strncpy(tmp+strlen(tmp), req->lfile, MAXBUFSIZ - strlen(tmp) - 3);
	strncpy(req->lfile, tmp, MAXBUFSIZ - 2);

	/* If a log file for a previous try has been found, read it and
	 * resume the download job (resume_get), otherwise, start with
	 * a clean job (get)
	 *
	 * Logfile is of the pattern: aget-$file_name.log
	 */
	switch(req->proto) {
		case PROTO_HTTP:
			if ((retlog = read_log(&h)) != -1)
				resumeDownload(&h, PROTO_HTTP);
			else
				startHTTP(req);
			break;
		case PROTO_FTP:
			if ((retlog = read_log(&h)) != -1)
				resumeDownload(&h, PROTO_FTP);
			else
				startFTP(req);
			break;
	}
	return 0;
}
Example #20
0
PROJECT_DATA * read_project( FILE *fp )
{
    PROJECT_DATA *project;
    NOTE_DATA *log, *tlog;
    char *word;
    char buf [MSL];
    bool fMatch;
    char letter;

    do
    {
        letter = getc( fp );
        if( feof(fp) )
        {
            fclose( fp );
            return NULL;
        }
    }

    while( isspace(letter) )
        ;
    ungetc( letter, fp );

    project = alloc_mem( sizeof( PROJECT_DATA ) );

    project->first_log = NULL;
    project->next       = NULL;
    project->coder = NULL;
    project->description = str_dup("");
    project->name = str_dup( "" );
    project->owner = str_dup( "" );
    project->date = str_dup( "Not Set?!");
    project->status = str_dup( "No update." );

    for ( ; ; )
    {
        word   = feof( fp ) ? "End" : fread_word( fp );
        fMatch = FALSE;

        switch ( UPPER(word[0]) )
        {
        case '*':
            fMatch = TRUE;
            fread_to_eol( fp );
            break;
	case 'C':
		KEY("Coder",	project->coder,fread_string( fp )  );
		break;
	case 'D':
		if (!str_cmp(word, "Date") )
			free_string(project->date);
		else if ( !str_cmp(word, "Description") )
			free_string(project->description);
		KEY("Date",		project->date,fread_string( fp ));		
	   	KEY("Description",project->description,fread_string(fp));
		break;
        case 'E':
            if ( !str_cmp( word, "End" ) )
            {   
                if ( !project->description )
                    project->description = str_dup( "" );
                if ( !project->name )
                    project->name = str_dup( "" );
                if ( !project->owner )
                    project->owner = str_dup( "" );
                if ( !project->date )
	        project->date = str_dup( "Not Set?!" );
                if ( !project->status )
                    project->status = str_dup( "No update." );
                if ( str_cmp(project->owner, "None") )
                    project->taken = TRUE;
                return project;
            }
            break;
	case 'L':
	    if( !str_cmp( word, "Log" ) )
	    {
		fread_to_eol( fp );
		log = read_log( fp );
		if( !log )
		{
		   xprintf( buf, "read_project: couldn't read log,aborting");
		   bug( buf, 0 );
		   exit( 1 );
	        }
		if(!log->sender)
		  log->sender = str_dup( "" );
		if(!log->date)
		  log->date   = str_dup( "" );
		if(!log->subject)
		  log->subject = str_dup( "None" );
		  log->to_list = str_dup( "" );
                  if( !project->first_log )
                      project->first_log = log;
                  else
                  {
                      log->next = project->first_log;
                      project->first_log = log;
                  }

		fMatch = TRUE;
		break;
	    }
		break;
	case 'N':
	    KEY( "Name", 		project->name,fread_string( fp )  );
		break;
	case 'O':
	    KEY( "Owner", 		project->owner,fread_string( fp ) );
		break;
	case 'S':
	    KEY( "Status", 		project->status,fread_string( fp ) );
		break;
        }
        if ( !fMatch ) 
        {
            xprintf( buf, "read_project: no match: %s", word );
            bug( buf, 0 );
        }
    }


    for( log = project->first_log; log; log = tlog )
    {
          tlog = log->next;
          free_string( log->text    );
          free_string( log->subject );
          free_string( log->to_list );
          free_string( log->date    );
          free_string( log->sender  );
          log->next = note_free;
          note_free   = log;
    }
    project->first_log =NULL;
    if ( project->coder )
        free_string( project->coder );
    if ( project->description )
        free_string( project->description );
    if ( project->name )
        free_string( project->name );
    if ( project->owner )
        free_string( project->owner );
    if ( project->date )
        free_string( project->date );
    if ( project->status )
        free_string( project->status );

    free_mem( project, sizeof( PROJECT_DATA ) );
    return project;
}