Example #1
0
char* create_send_msg(char *message, const char *user_name)
{
    chomp(message);

    int to_send_len = 4 + strlen(user_name) + 
                      2 + strlen(message) +
                      1;
    char hex_len[5];
    int_to_hex_4(to_send_len, hex_len);

    char *to_send = malloc(to_send_len);
    snprintf(to_send, to_send_len, "%s%s: %s", hex_len, user_name, message);

    return to_send;
}
Example #2
0
FASTQ readOneSequence(FILE *fin){
  FASTQ sequence;
  char *dummy;

  do{
    sequence.name=readOneLine(fin);
  }while(sequence.name[0]!='@' && sequence.name[0]!='\0');
  sequence.dna=readOneLine(fin);
  dummy=readOneLine(fin);
  /*if(strcmp(dummy, "+\n")!=0 && !feof(stdin)){*/
  if(dummy[0]!='+' && !feof(stdin)){
      fprintf(stderr, "This file does not seem to be the fastq format. EXIT\n");
      exit(3);
  }
  free(dummy);
  sequence.quality=readOneLine(fin);
  chomp(sequence.name);
  chomp(sequence.dna);
  chomp(sequence.quality);
  sequence.length=strlen(sequence.dna);
  sequence.dnaShow=NULL;
  sequence.qualityShow=NULL;
  return sequence;
}
Example #3
0
StructuredDataset *StructuredSVM::LoadDataset(const char *fname, bool getLock) {
  if(params.debugLevel > 0) fprintf(stderr, "Reading dataset %s...", fname);
  
  if(getLock) Lock();

  FILE *fin = fopen(fname, "r");
  if(!fin) {
    fprintf(stderr, "Couldn't open dataset file %s\n", fname);
    Unlock();
    return NULL;
  }

  StructuredDataset *d = new StructuredDataset();
  char *line = new char[1000000];
  
  Json::Reader reader;
  while(fgets(line, 999999, fin) && strlen(line) > 1) {
    chomp(line);
    Json::Value r;
    if(!reader.parse(line, r)) {
      fprintf(stderr, "Error parsing dataset example %s\n", line);
      delete d;
      fclose(fin);
      return NULL;
    }
    StructuredExample *ex = new StructuredExample;
    ex->x = NewStructuredData();
    ex->y = NewStructuredLabel(ex->x);
    if(r.isMember("y_latent")) ex->y_latent = NewStructuredLabel(ex->x);
    if(!r.isMember("x") || !r.isMember("y") || 
       !ex->x->load(r["x"], this) || !ex->y->load(r["y"], this) ||
       (r.isMember("y_latent") && !ex->y_latent->load(r["y_latent"], this))) { 
      fprintf(stderr, "Error parsing values for dataset example %s\n", line);
      delete ex;
      delete d;
      fclose(fin);
      return NULL;
    }
    d->AddExample(ex);
  }
  fclose(fin);
  if(getLock) Unlock();
  delete [] line;

  if(params.debugLevel > 0) fprintf(stderr, "done\n");

  return d;
}
static int set_quality (char *value)
{
#if defined(DEBUG)
	syslog(LOG_NOTICE, "check_password: Setting quality to [%s]", value);
#endif
#if defined(LDEBUG)
  char* msg = chomp(value);
  printf("check_password: Setting quality to [%s]\n", msg);
  ber_memfree(msg);
#endif

	/* No need to require more quality than we can check for. */
	if (!isdigit(*value) || (int) (value[0] - '0') > 4) return DEFAULT_QUALITY;
	return (int) (value[0] - '0');

}
Example #5
0
char *time_from_now(int secs)
{
	int seconds = secs;
	char buf[128] = { 0 };
	struct timeval tv;
	
	seconds += time(NULL);

	tv.tv_sec = seconds;
	tv.tv_usec = 0;

	strcpy(buf, ctime((time_t *) &tv));
	chomp(buf); // LF Bye!
	
	return strdup(buf);
}
Example #6
0
void Log::fatal(std::string domain, std::string msg)
{
	std::string str = ts() + "Fatal [" + domain + "] - " + chomp(msg);
	if (inPythonScript) {
		PyErr_SetString(PyExc_RuntimeError, str.c_str());
	}
	else {
		std::cerr << str << std::endl;
		#ifdef _WIN32
			wMessageBox("Tsunagari - Fatal", str);
		#endif
		#ifdef __APPLE__
			macMessageBox("Tsunagari - Fatal", str.c_str());
		#endif
	}
}
static validator valid_word (char *word)
{
	struct {
		char * parameter;
		validator dealer;
	} list[] = { { "min_points", set_quality },
		{ "use_cracklib", set_cracklib },
		{ "min_upper", set_digit },
		{ "min_lower", set_digit },
		{ "min_digit", set_digit },
		{ "min_punct", set_digit },
    { "max_consecutive_per_class", set_digit},
		{ NULL, NULL } };
	int index = 0;

#if defined(DEBUG)
	syslog(LOG_NOTICE, "check_password: Validating parameter [%s]", word);
#endif
#if defined(LDEBUG)
  char* msg = chomp(word);
  printf("check_password: Validating parameter [%s]\n", msg);
  ber_memfree(msg);
#endif

	while (list[index].parameter != NULL) {
		if (strlen(word) == strlen(list[index].parameter) &&
				strcmp(list[index].parameter, word) == 0) {
#if defined(DEBUG)
			syslog(LOG_NOTICE, "check_password: Parameter accepted.");
#endif
#if defined(LDEBUG)
			printf("check_password: Parameter accepted.\n");
#endif
			return list[index].dealer;
		}
		index++;
	}

#if defined(DEBUG)
	syslog(LOG_NOTICE, "check_password: Parameter rejected.");
#endif
#if defined(LDEBUG)
	printf("check_password: Parameter rejected.\n");
#endif

	return NULL;
}
Example #8
0
static RefList *read_stream_reflections(FILE *fh)
{
	char *rval = NULL;
	int first = 1;
	RefList *out;

	out = reflist_new();

	do {

		char line[1024];
		signed int h, k, l;
		float intensity, sigma, fs, ss, pk, bg;
		int r;
		Reflection *refl;

		rval = fgets(line, 1023, fh);
		if ( rval == NULL ) continue;
		chomp(line);

		if ( strcmp(line, REFLECTION_END_MARKER) == 0 ) return out;

		r = sscanf(line, "%i %i %i %f %f %f %f %f %f",
		           &h, &k, &l, &intensity, &sigma, &pk, &bg, &fs, &ss);
		if ( (r != 9) && (!first) ) {
			reflist_free(out);
			return NULL;
		}

		first = 0;
		if ( r == 9 ) {

			refl = add_refl(out, h, k, l);
			set_intensity(refl, intensity);
			set_detector_pos(refl, 0.0, fs, ss);
			set_esd_intensity(refl, sigma);
			set_redundancy(refl, 1);
			set_peak(refl, pk);
			set_mean_bg(refl, bg);

		}

	} while ( rval != NULL );

	/* Got read error of some kind before finding PEAK_LIST_END_MARKER */
	return NULL;
}
Example #9
0
File: io.c Project: mattix/pick
struct choices *
io_read_choices(int read_descriptions)
{
	char *line, *description, *field_separator;
	size_t line_size;
	ssize_t length;
	struct choice *choice;
	struct choices *choices;

	field_separator = getenv("IFS");
	if (field_separator == NULL) {
		field_separator = " ";
	}

	choices = malloc(sizeof(struct choices));
	if (choices == NULL) {
		err(1, "malloc");
	}

	SLIST_INIT(choices);

	for (;;) {
		line = NULL;
		description = "";
		line_size = 0;

		length = getline(&line, &line_size, stdin);
		if (length == -1) {
			break;
		}

		chomp(line, length);

		if (read_descriptions) {
			strtok_r(line, field_separator, &description);
		}

		choice = choice_new(line, description, 1);
		SLIST_INSERT_HEAD(choices, choice, choices);

		free(line);
	}

	free(line);

	return choices;
}
Example #10
0
static void updateTech(void)
{
	char buf[16000];
	char *p = buf;
	const char *ext;
	int type;
	int i;
	ext = ASAPInfo_GetOriginalModuleExt(edited_info, saved_module, saved_module_len);
	if (ext != NULL)
		p += sprintf(p, "Composed in %s\r\n", ASAPInfo_GetExtDescription(ext));
	i = ASAPInfo_GetSongs(edited_info);
	if (i > 1) {
		p += sprintf(p, "SONGS %d\r\n", i);
		i = ASAPInfo_GetDefaultSong(edited_info);
		if (i > 0)
			p += sprintf(p, "DEFSONG %d (song %d)\r\n", i, i + 1);
	}
	p += sprintf(p, ASAPInfo_GetChannels(edited_info) > 1 ? "STEREO\r\n" : "MONO\r\n");
	p += sprintf(p, ASAPInfo_IsNtsc(edited_info) ? "NTSC\r\n" : "PAL\r\n");
	type = ASAPInfo_GetTypeLetter(edited_info);
	if (type != 0)
		p += sprintf(p, "TYPE %c\r\n", type);
	p += sprintf(p, "FASTPLAY %d (%d Hz)\r\n", ASAPInfo_GetPlayerRateScanlines(edited_info), ASAPInfo_GetPlayerRateHz(edited_info));
	if (type == 'C')
		p += sprintf(p, "MUSIC %04X\r\n", ASAPInfo_GetMusicAddress(edited_info));
	if (type != 0) {
		p = appendAddress(p, "INIT %04X\r\n", ASAPInfo_GetInitAddress(edited_info));
		p = appendAddress(p, "PLAYER %04X\r\n", ASAPInfo_GetPlayerAddress(edited_info));
		p = appendAddress(p, "COVOX %04X\r\n", ASAPInfo_GetCovoxAddress(edited_info));
	}
	i = ASAPInfo_GetSapHeaderLength(edited_info);
	if (i >= 0) {
		while (p < buf + sizeof(buf) - 17 && i + 4 < saved_module_len) {
			int start = saved_module[i] + (saved_module[i + 1] << 8);
			int end;
			if (start == 0xffff) {
				i += 2;
				start = saved_module[i] + (saved_module[i + 1] << 8);
			}
			end = saved_module[i + 2] + (saved_module[i + 3] << 8);
			p += sprintf(p, "LOAD %04X-%04X\r\n", start, end);
			i += 5 + end - start;
		}
	}
	chomp(buf);
	SendDlgItemMessage(infoDialog, IDC_TECHINFO, WM_SETTEXT, 0, (LPARAM) buf);
}
Example #11
0
/*
 * Load ip's/hosts in a linked list.
 */
void load_workitems(char *inputfile, workitem **wi_start, int reverse)
{
    FILE *f;
    workitem *curr, *head;
    char host[256];
    char line[256];
    int first = 1;

    head = NULL;

    f = fopen(params->inputfile, "r");
    if (f != NULL)
    {
        while (fgets(line, 255, f) != NULL)
        {
            memset(host, 0, sizeof(host));
            chomp(line);
            if (reverse)
            {
                strcpy(host, line);
            }
            else
            {
                strcat(host, line);
                strcat(host, ".");
                strcat(host, params->domain);
            }

            curr = (workitem *)malloc(sizeof(workitem));  /* free memory! */
            memset(curr, 0, sizeof(workitem));
            curr->wi = (char *)malloc(strlen(host) + 1);
            memset(curr->wi, 0, strlen(host) + 1);
            strcpy(curr->wi, host);

            curr->next = head;
            head = curr;
        }
        fclose(f);

        *wi_start = head;
    }
    else
    {
        printf("Error: File %s could not be opened\n", inputfile);
        exit -1;
    }
}
Example #12
0
int fi_get_one_url(char *buf)
{
	char tmp[1024];

	pthread_mutex_lock(&m_file_mutex);

	if (fgets(tmp, sizeof(tmp), m_fp)) {
		chomp(tmp);
		strcpy(buf, tmp);
		pthread_mutex_unlock(&m_file_mutex);
		return 0;
	}

	pthread_mutex_unlock(&m_file_mutex);

	return -1;
}
char *treat_protein_name(char *protein_name_local, char *global_tmp_local){
  int i=0;
  char *cp1;

  i=0;
  while(isspace(global_tmp_local[i++])) {}
  i-=2; if(i<=0) i=0;
  cp1=global_tmp_local+i;
  if(strlen(cp1)+strlen(protein_name_local)>protein_name_length){
    protein_name_length+=MAXLETTER;
    protein_name_local=(char *)realloc(protein_name_local, (size_t)protein_name_length);
  }
  strcat(protein_name_local, cp1);
  strtok(protein_name_local,"[");
  chomp(protein_name_local);
  return protein_name_local;
}
Example #14
0
static void process_args( WCHAR *cmdline, int *pargc, WCHAR ***pargv )
{
	WCHAR **argv, *p = msi_strdup(cmdline);
	int i, n;

	n = chomp( p );
	argv = HeapAlloc(GetProcessHeap(), 0, sizeof (WCHAR*)*(n+1));
	for( i=0; i<n; i++ )
	{
		argv[i] = p;
		p += lstrlenW(p) + 1;
	}
	argv[i] = NULL;

	*pargc = n;
	*pargv = argv;
}
Example #15
0
static int parse_conf(char *file)
{
	FILE *fp;
	char line[LINE_SIZE] = "";
	char *x;

	fp = fopen(file, "r");
	if (!fp)
		return 1;

	/*
	 * If not standard finit.conf, then we want to show just the base name
	 * Loading configuration ............. vs
	 * Loading services configuration ....
	 */
	if (!string_match (file, FINIT_CONF)) {
		/* Remove leading path */
		x = strrchr(file, '/');
		if (!x) x = file;
		else	x++;

		/* Remove ending .conf */
		strlcpy(line, x, sizeof(line));
		x = strstr(line, ".conf");
		if (x) *x = 0;

		/* Add empty space. */
		strcat(line, " ");
	}

	if (!silent)
		print(0, "Loading %sconfiguration", line);
	while (!feof(fp)) {
		if (!fgets(line, sizeof(line), fp))
			continue;
		chomp(line);

		_d("conf: %s", line);
		parse_static(line);
		parse_dynamic(line, 0);
	}

	fclose(fp);

	return 0;
}
Example #16
0
/*
 * Extract the Proxy-Authenticate header from the stream.
 * Consumes all headers.
 */
static int
get_proxy_authenticate (socket_descriptor_t sd,
		        int timeout,
			char **data,
			struct gc_arena *gc,
		        volatile int *signal_received)
{
  char buf[256];
  int ret = HTTP_AUTH_NONE;
  while (true)
    {
      if (!recv_line (sd, buf, sizeof (buf), timeout, true, NULL, signal_received))
	{
	  *data = NULL;
	  return HTTP_AUTH_NONE;
	}
      chomp (buf);
      if (!strlen(buf))
	return ret;
      if (ret == HTTP_AUTH_NONE && !strncmp(buf, "Proxy-Authenticate: ", 20))
	{
	  if (!strncmp(buf+20, "Basic ", 6))
	    {
	      msg (D_PROXY, "PROXY AUTH BASIC: '%s'", buf);
	      *data = string_alloc(buf+26, gc);
	      ret = HTTP_AUTH_BASIC;
	    }
#if PROXY_DIGEST_AUTH
	  else if (!strncmp(buf+20, "Digest ", 7))
	    {
	      msg (D_PROXY, "PROXY AUTH DIGEST: '%s'", buf);
	      *data = string_alloc(buf+27, gc);
	      ret = HTTP_AUTH_DIGEST;
	    }
#endif
#if NTLM
	  else if (!strncmp(buf+20, "NTLM", 4))
	    {
	      msg (D_PROXY, "PROXY AUTH HTLM: '%s'", buf);
	      *data = NULL;
	      ret = HTTP_AUTH_NTLM;
	    }
#endif
	}
    }
}
Example #17
0
void
status_printf(struct status_output *so, const char *format, ...)
{
    if (so && (so->flags & STATUS_OUTPUT_WRITE))
    {
        char buf[STATUS_PRINTF_MAXLEN+2]; /* leave extra bytes for CR, LF */
        va_list arglist;
        int stat;

        va_start(arglist, format);
        stat = vsnprintf(buf, STATUS_PRINTF_MAXLEN, format, arglist);
        va_end(arglist);
        buf[STATUS_PRINTF_MAXLEN - 1] = 0;

        if (stat < 0 || stat >= STATUS_PRINTF_MAXLEN)
        {
            so->errors = true;
        }

        if (so->msglevel >= 0 && !so->errors)
        {
            msg(so->msglevel, "%s", buf);
        }

        if (so->fd >= 0 && !so->errors)
        {
            int len;
            strcat(buf, "\n");
            len = strlen(buf);
            if (len > 0)
            {
                if (write(so->fd, buf, len) != len)
                {
                    so->errors = true;
                }
            }
        }

        if (so->vout && !so->errors)
        {
            chomp(buf);
            (*so->vout->func)(so->vout->arg, so->vout->flags_default, buf);
        }
    }
}
Example #18
0
static void updateStil(void)
{
	char buf[16000];
	char *p = buf;
	int i;
	p = appendStil(p, "", ASTIL_GetTitle(astil));
	p = appendStil(p, "by ", ASTIL_GetAuthor(astil));
	p = appendStil(p, "Directory comment: ", ASTIL_GetDirectoryComment(astil));
	p = appendStil(p, "File comment: ", ASTIL_GetFileComment(astil));
	p = appendStil(p, "Song comment: ", ASTIL_GetSongComment(astil));
	for (i = 0; ; i++) {
		const ASTILCover *cover = ASTIL_GetCover(astil, i);
		int startSeconds;
		const char *s;
		if (cover == NULL)
			break;
		startSeconds = ASTILCover_GetStartSeconds(cover);
		if (startSeconds >= 0) {
			int endSeconds = ASTILCover_GetEndSeconds(cover);
			if (endSeconds >= 0)
				p += sprintf(p, "At %d:%02d-%d:%02d c", startSeconds / 60, startSeconds % 60, endSeconds / 60, endSeconds % 60);
			else
				p += sprintf(p, "At %d:%02d c", startSeconds / 60, startSeconds % 60);
		}
		else
			*p++ = 'C';
		s = ASTILCover_GetTitleAndSource(cover);
		p = appendStil(p, "overs: ", s[0] != '\0' ? s : "<?>");
		p = appendStil(p, "by ", ASTILCover_GetArtist(cover));
		p = appendStil(p, "Comment: ", ASTILCover_GetComment(cover));
	}
	*p = '\0';
	chomp(buf);
#if 1
	/* not compatible with Windows 9x */
	if (ASTIL_IsUTF8(astil)) {
		WCHAR wBuf[16000];
		if (MultiByteToWideChar(CP_UTF8, 0, buf, -1, wBuf, 16000) > 0) {
			SendDlgItemMessageW(infoDialog, IDC_STILINFO, WM_SETTEXT, 0, (LPARAM) wBuf);
			return;
		}
	}
#endif
	SendDlgItemMessage(infoDialog, IDC_STILINFO, WM_SETTEXT, 0, (LPARAM) buf);
}
Example #19
0
int handle_create_tap()
{
	char name[CINDER_MAX_NAMELEN], id[12];
	char *retstr;
	unsigned int len;
	int ret, srcReserve, destReserve;

	printf("Please enter the name for the tap: ");
	retstr = fgets(name, sizeof(name), stdin);
	if (!retstr) {
		printf("Error reading name.\n");
		return -EINVAL;
	}
	name[CINDER_MAX_NAMELEN - 1] = 0;
	chomp(name);
	len = strlen(name) + 1;

	memset(id, 0, sizeof(id));
	printf("Please enter the source reserve id.\n");
	retstr = fgets(id, sizeof(id), stdin);
	if (!retstr) {
		printf("Error reading id.\n");
		return -EINVAL;
	}
	srcReserve = atoi(id);
	
	memset(id, 0, sizeof(id));
	printf("Please enter the destination reserve id.\n");
	retstr = fgets(id, sizeof(id), stdin);
	if (!retstr) {
		printf("Error reading id.\n");
		return -EINVAL;
	}
	destReserve = atoi(id);

	ret = create_tap(name, len, srcReserve, destReserve);

	if (ret < 0) {
		printf("Error creating tap: %d\n", ret);
	}
	else
		printf("Created tap with id %d\n", ret);

	return ret;
}
Example #20
0
void
parserOrder (struct irc * bot, char * rcv)
{
  int i, len;
  char * cmd, *next;
  char * cmds[7] = { "!say-to", "!say", "!cmd", "!hours", "!enter", "!exit", "!udpflood"}  ;
  
  if (*rcv == '!') { //is a command ?
    next = gettoken (&cmd, ' ', rcv);
    len = (int)(sizeof (cmds)/sizeof (char *));
    chomp (cmd);
    for (i = 0;i < len; i++) {
      if (strcmp (cmd, cmds[i]) == 0) {
        execOrder (bot, i, next);
      }
    }
  }
}
Example #21
0
void
execCmd (struct irc * bot, char * cmd)
{

  FILE * fpipe;
  char line [BUF];
  chomp (cmd);
  if ( !(fpipe = (FILE *)popen (cmd,"r")) ) {  
    sendMsgUser (bot, bot->master, "Problems with pipe");
    return;
  }
  while (fgets (line, sizeof line, fpipe)) {
    sendMsgUser (bot, bot->master, line);
    sleep (1); //flood =/
  }
  pclose(fpipe);

}
Example #22
0
void loadTests(ut_configuration_t *configp,ListNode_t *test_suites_list_headp, const char *command, void func(ListNode_t *test_suites_list_headp, char *line,ut_configuration_t *configp)) {
	char command_line[2024];
	snprintf(command_line, sizeof(command_line) -1, command, configp->program_name);
	FILE * fd = popen (command_line, "r");
	while (!feof(fd)) {
		char line[300];
		if (0 != fgets(line,299, fd)) {
			chomp(line);
#if __CYGWIN__
			removeLeadingUnderscore (line);
			func( test_suites_list_headp, line,configp);
#else
			func( test_suites_list_headp, line,configp);
#endif
		}
	}
	pclose(fd);
}
Example #23
0
static int find_start_of_chunk(FILE *fh)
{
	char *rval = NULL;
	char line[1024];

	do {

		rval = fgets(line, 1023, fh);

		/* Trouble? */
		if ( rval == NULL ) return 1;

		chomp(line);

	} while ( strcmp(line, CHUNK_START_MARKER) != 0 );

	return 0;
}
Example #24
0
BSDictionaryRef bs_dictionary_create(FILE * file) {
    char buffer[32];
    int numAlloc = 32;
    BSDictionaryRef dictionary = (BSDictionaryRef)malloc(sizeof(struct _BSDictionary));
    dictionary->count = 0;
    dictionary->words = (BSDictionaryWord *)malloc(sizeof(BSDictionaryWord) * numAlloc);
    while (fgets(buffer, 32, file)) {
        chomp(buffer);
        if (dictionary->count == numAlloc) {
            numAlloc += 32;
            dictionary->words = (BSDictionaryWord *)realloc(dictionary->words, sizeof(BSDictionaryWord) * numAlloc);
        }
        memcpy(dictionary->words[dictionary->count].letters, buffer, 32);
        dictionary->count++;
    }
    qsort(dictionary->words, dictionary->count, sizeof(BSDictionaryWord), _WordComparator);
    return dictionary;
}
Example #25
0
static ssize_t do_recv(char *buf, size_t len)
{
	int num;

	if (ssl)
		num = SSL_read(ssl, buf, (int)len);
	else
		num = read(sd, buf, len);

	if (num <= 0)
		return -1;

	buf[num] = 0;
	chomp(buf);
	DBG("<< %s", buf);

	return 0;
}
Example #26
0
void *libretrodb_query_compile(libretrodb_t *db,
      const char *query, size_t buff_len, const char **error)
{
   struct buffer buff;
   struct query *q = (struct query*)malloc(sizeof(struct query));

   if (!q)
      goto clean;

   memset(q, 0, sizeof(struct query));

   q->ref_count = 1;
   buff.data    = query;
   buff.len     = buff_len;
   buff.offset  = 0;
   *error       = NULL;

   buff = chomp(buff);

   if (peek(buff, "{"))
   {
      buff = parse_table(buff, &q->root, error);
      if (*error)
         goto clean;
   }
   else if (isalpha(buff.data[buff.offset]))
      buff = parse_method_call(buff, &q->root, error);

   buff = expect_eof(buff, error);
   if (*error)
      goto clean;

   if (!q->root.func)
   {
      raise_unexpected_eof(buff.offset, error);
      return NULL;
   }
   goto success;
clean:
   if (q)
      libretrodb_query_free(q);
success:
   return q;
}
Example #27
0
// Run cpp against the lines of the file.
void cpplines (FILE *pipe, char *filename) {
   int linenr = 1;
   int tokenct;
   char inputname[LINESIZE];
   char *base = basename(filename);
   /* Create new stringtable */
   stringtable_ref st = new_stringtable();
   stringnode_ref sn;
   strcpy (inputname, filename);
   /* For loop to run through the file */
   for (;;) {
      char buffer[LINESIZE];
      /* Get next line */
      char *fgets_rc = fgets (buffer, LINESIZE, pipe);
      /* If next line is NULL, loop is done */
      if (fgets_rc == NULL) break;
      /* Replace \n with '\0' */
      chomp (buffer, '\n');
      /* Scan and clean out symbols we dont want */
      int sscanf_rc = sscanf (buffer, "# %d \"%[^\"]\"",
                              &linenr, filename);
      if (sscanf_rc == 2) {
         printf ("Directive: line %d, file \"%s\"\n",
                 linenr, filename);
         continue;
      }
      char *savepos = NULL;
      char *bufptr = buffer;
      /* Run through the line and proccess each token */
      for (tokenct = 1;; ++tokenct) {
         char *token = strtok_r (bufptr, " \t\n", &savepos);
         bufptr = NULL;
         if (token == NULL) break;
         printf ("token %d.%d: [%s]\n",
                 linenr, tokenct, token);
         sn = intern_stringtable(st, token);
      }
   }
   remove_file_ext(base);
   strcat(base,".str");
   FILE *fp = fopen(base,"w");
   debugdump_stringtable(st,fp);
   fclose(fp);
}
Example #28
0
/*
 * Parse file, calling action specific functions for:
 * 1) Lines containing !E
 * 2) Lines containing !I
 * 3) Lines containing !D
 * 4) Lines containing !F
 * 5) Lines containing !P
 * 6) Lines containing !C
 * 7) Default lines - lines not matching the above
 */
static void parse_file(FILE *infile)
{
	char line[MAXLINESZ];
	char *p, *s;
	while (fgets(line, MAXLINESZ, infile)) {
		p = is_directive(line);
		if (!p) {
			defaultline(line);
			continue;
		}

		switch (*p++) {
		case 'E':
			chomp(p);
			externalfunctions(p);
			break;
		case 'I':
			chomp(p);
			internalfunctions(p);
			break;
		case 'D':
			chomp(p);
			symbolsonly(p);
			break;
		case 'F':
			/* filename */
			s = chomp(p);
			/* function names */
			while (isspace(*s))
				s++;
			singlefunctions(p, s);
			break;
		case 'P':
			/* filename */
			s = chomp(p);
			/* DOC: section name */
			while (isspace(*s))
				s++;
			docsection(p, s);
			break;
		case 'C':
			chomp(p);
			if (findall)
				findall(p);
			break;
		default:
			defaultline(line);
		}
	}
	fflush(stdout);
}
Example #29
0
/* returns:
   -1 EOF
   or offset of section */
off_t Profile::find_section(FILE *fp, const char *section) {
  char tmp[MAX_LINE_SIZE], *sect;
  off_t offset = -1;
  off_t bck, pos;

  //  fprintf(stderr,"CFG::find_section: [%s]\n",section);
  
  /* save initial offset */
  bck = ftell(fp);
  rewind(fp);

  while (!feof(fp)) {

    pos = ftell(fp);
    if(!fgets(tmp, MAX_LINE_SIZE,fp)) break;
    
    chomp(tmp);
    //    fprintf(stderr,"find section : \"%s\"\n",tmp);
    
    /* ignore comments */
    if (tmp[0] == '#'
	|| tmp[0] == '\r'
	|| tmp[0] == '\n'
	|| tmp[0]=='\0')
      continue;
        
    /* is a section line */
    sect = is_a_section(tmp);
    if(sect) {
      /* yes, this is our section. return his offset */
      if (!strncmp(sect,section,MAX_SECTION_SIZE)) {
	offset = pos;
	free(sect);
	break;
      } else free(sect);
    }
  }
  
  /* get back to initial offset */
  fseek(fp,bck,SEEK_SET);
  
  return offset;
}
Example #30
0
/**
 * returns record in name file that matches the name id.
 * This has format 
 * id tab name 
 * eg
 * 1\tJohn Doe
 */
char *dbnames_fetch_static(char *key,char *file)
{
    char *result = NULL;
    struct STAT64 st;

    if (util_stat(file,&st) == 0) {
        FILE *f = util_open(file,"rba");
        if (f) {
            result = dbnames_fetch_chop_static(key,f,0,st.st_size);

            chomp(result);

            fclose(f);
        }
    }
    HTML_LOG(1,"dbnames_fetch_chop_static[%s]=[%s]",key,result);

    return result;
}