Example #1
0
/*ARGSUSED*/
static int
socket_vop_close(struct vnode *vp, int flag, int count, offset_t offset,
    struct cred *cr, caller_context_t *ct)
{
	struct sonode *so;
	int error = 0;

	so = VTOSO(vp);
	ASSERT(vp->v_type == VSOCK);

	cleanlocks(vp, ttoproc(curthread)->p_pid, 0);
	cleanshares(vp, ttoproc(curthread)->p_pid);

	if (vp->v_stream)
		strclean(vp);

	if (count > 1) {
		dprint(2, ("socket_vop_close: count %d\n", count));
		return (0);
	}

	mutex_enter(&so->so_lock);
	if (--so->so_count == 0) {
		/*
		 * Initiate connection shutdown.
		 */
		mutex_exit(&so->so_lock);
		error = socket_close_internal(so, flag, cr);
	} else {
		mutex_exit(&so->so_lock);
	}

	return (error);
}
Example #2
0
char* text_getText(text_t self){
	static char text[MAX_SIZE_OF_SENTENCE*MAX_AMOUNT_OF_SENTENCES];
	strclean(text);
	for (int i = 0; i < self->amountOfSentences; i++){
		strcat(text, self->sentences[i]);
		if (text[strlen(text)-1] != '.') strcat(text, ".");
		strcat(text, " ");
	}
	self->status = OK;
	return text;
}
Example #3
0
int GetChannelNames(int list_channels)
{
   int fd,i,n;
   unsigned short sid;
   channel_name_t *channel_name;
   
   if((fd = open("ChannelNames",O_RDWR)) < 0)
   {
      perror("ChannelNames : ");
      return -1;
   }
   //   SetFiltSection (fd, 211, 0x91);
   n = read(fd,buffer,MAX_SECTION_BUFFER);
   if (n <= 0)
   {
      fprintf (stderr, "Error while reading channels names\n");
      perror(":");
      return -1;
   }
   //   ioctl(fd, DMX_STOP);
   close (fd);

   channel_name = (channel_name_t *) (buffer+4);
   nb_channels = (n-4)/sizeof(channel_name_t);
   if (nb_channels >= MAX_CHANNELS)
   {
      fprintf (stderr, "Channels Table overflow (%d names needed)\n", nb_channels);
      return -1;
   }

   for (i=0; i<nb_channels; i++)
   {
      sid = HILO (channel_name->channel_id);

      memcpy (channels[i], channel_name -> name, 16);
      channels[i][16] = 0;
      /* Remove trailing blanks */
      strclean (channels[i]);
      if (source[0] != 0)
	      sprintf (channel_ids[i], "%s-%d-%d-%d",source,HILO (channel_name->network_id),HILO (channel_name->transponder_id), HILO (channel_name->channel_id));
      else
	      sprintf (channel_ids[i], "%d", HILO (channel_name->channel_id));
#ifdef DEBUG
      fprintf (stderr,"SID = %s   CHANNEL = '%s'\n",channel_ids[i], channels[i]);
#endif
	if (list_channels)
	      fprintf (stderr,"%s %s\n",channel_ids[i], channels[i]);
      channel_name++;
   }
   return 0;
}
Example #4
0
int f77name(messerr)(char message[], F2Cl flen)
{
   char longMessage[256];
   int lng;
   int len=flen;

   message[len-1] = '\0';
   lng = c_getulng();

   strclean(message);
   strcpy(longMessage, finiRaide[lng]);
   strcat(longMessage, message);
   
   MessageErreur(longMessage);
   return 0;
   }
Example #5
0
void text_addSentenceByIndex(text_t self, char* sentence, int index){
	if (index > self->amountOfSentences || index < 0){
		self->status = INDEX_OUT_OF_BOUND;
		return;
	}
	if (sentence == NULL){
		self->status = NULL_POINTER;
		return;
	}
	self->sentences[self->amountOfSentences] = (char*)malloc(MAX_SIZE_OF_SENTENCE*sizeof(char));
	self->amountOfSentences++;
	for (int i = self->amountOfSentences - 1; i > index; i--){
		memcpy(self->sentences[i], self->sentences[i - 1], MAX_SIZE_OF_SENTENCE*sizeof(char));
	}
	strclean(self->sentences[index]);
	strcpy(self->sentences[index], sentence);
	self->status = OK;
}
Example #6
0
void cfg_Init(char *fn)
{
	char temp[80];
	config_key *cf;

	GetCurrentDirectory(255, cfgfn);
	strcat(cfgfn, va("\\%s",fn));
	cf_top = 0;

	FILE *f = fopen(fn, "r");
	if (!f) return;

	cf = 0;
	while (!feof(f))
	{
		fscanf(f,"%s%*c", temp);
		if (strlen(temp)>1 && isletter(temp[0]) && !feof(f)) 
		{
			if (strlen(temp)>=KEYSIZE)
				err("cfg_Init(), key too big");
			if (!cf) 
				cf = cf_top = (config_key *) malloc(sizeof config_key);
			else 
			{	
				cf->next = (config_key *) malloc(sizeof config_key);
				cf = cf->next;
			}
			
			strcpy(cf->keyname, temp);
			fgets(cf->value, VALUESIZE-1, f);
			strclean(cf->value);
			cf->next = 0;
		}
	}
	fclose(f);
}
Example #7
0
void cfg_Init(char *fn)
{
	char temp[1024];
	char line[1024];

	config_key *cf;
#ifdef __IPHONE__
	getcwd(cfgfn,255);
	strcat(cfgfn, va("/%s", fn));
#elif __APPLE__
	getcwd(cfgfn,255);
	strcat(cfgfn, va("/%s", fn));
#elif __LINUX__
	getcwd(cfgfn,255);
	strcat(cfgfn, va("/%s", fn));
#elif __PSP__
	//mbg 9/5/05
	//make the bold assumption that PWD has not been changed
	//and never will be
	//better handling might be required in the future
	sprintf(cfgfn,"%s",fn);
#elif __WII__
	//likewise above
	sprintf(cfgfn,"%s",fn);
#else 
	GetCurrentDirectory(255, cfgfn);
	strcat(cfgfn, va("\\%s",fn));
#endif
	cf_top = 0;

	FILE *f = fopen(cfgfn, "r");
	if (!f) return;

	cf = 0;
	while (!feof(f))
	{
		fgets(line, sizeof(line), f);
		// skip whitespace, read non-whitespace string then skip more whitespace
		int num_read = 0;
		sscanf(line," %s %n", temp, &num_read); // capture length read
		if (strlen(temp) > 0) // check for blank line
		{
			if(temp[0] == '#' || (temp[0] == '/' && temp[1] == '/')) {
				// comment - ignore until end of line
				continue;
			}

			if (strlen(temp)>=KEYSIZE)
				err("cfg_Init(), key too big");
			if (!cf)
				cf = cf_top = (config_key *) malloc(sizeof (config_key));
			else
			{
				cf->next = (config_key *) malloc(sizeof (config_key));
				cf = cf->next;
			}

			strcpy(cf->keyname, temp);
			cf->value[0] = '\0'; // ensure null-terminated value on error
			// now read non-whitespace string after key, up to VALUESIZE
			sscanf(line + num_read, " %" VALUESIZE_STR "s", cf->value);
			strclean(cf->value);
			cf->next = 0;
		}
	}
	fclose(f);
}
bool DIVMDKBlockStorage::parseDescriptor(DIBackingStore *backingStore,
                                         DILong offset, DIInt size)
{
    DIData data;
    
    if (!size)
        return true;
    
    data.resize(size * DI_BLOCKSIZE);
    
    if (!backingStore->read(offset * DI_BLOCKSIZE, &data.front(), size))
        return false;
    
    string s((const char *) &data.front(), data.size());
    stringstream ss(s);
    
    // Process lines
    string line;
    
    while (!ss.eof())
    {
        string line;
        
        getline(ss, line);
        
        // Disregard empty lines
        if (!line.size())
            continue;
        
        // Remove comments
        if (line[0] == '#')
            continue;
        
        // Process line
        vector<string> tokens = strsplit(line, '=');
        
        if (tokens.size() < 2)
            continue;
        
        string key = trim(tokens[0]);
        string value = strclean(trim(tokens[1]), " ");
        
        // Process dictionary
        if (key == "version")
        {
            if (value != "1")
                return false;
        }
        else if (key == "ddb.geometry.sectors")
            sectors = getDIInt(value);
        else if (key == "ddb.geometry.heads")
            heads = getDIInt(value);
        else if (key == "ddb.geometry.cylinders")
            cylinders = getDIInt(value);
        else if (key == "parentCID")
        {
            if (value != "ffffffff")
                return false;
        }
    }
    
    return true;
}
Example #9
0
int SaveEpgData(char * filename)
{
   FILE *file;
   struct summary * summary;
   int i,j,n,equiv_index;
   struct program * program;
   struct tm *next_date;
   int first_program;
   int index;
   u_char new_channel;
   time_t current_time;
   char channel_id[50];
   char long_title[81];
   int summary_found;
   char *ptr;
   
   fprintf (stderr,"Writing EPG data to file ...\n");
   current_time = time(NULL);
   /* Start from yesterday 6:00 */
   j = yesterday*24+6;
   for (i=0; i<24*7; i++)
      if ((first_program = hour_index[(i+j) % 24*7]) != -1)
         break;
#ifdef DEBUG
            fprintf (stderr,"First program = %d\n", first_program);
#endif
   if (first_program == -1)
      return -1;	/* No program */
   
   if (filename[0] != 0)
	file = fopen (filename,"w");
   else
        file = stdout;
   fprintf (stderr,"Nb of channels = %d\n", nb_channels);
   for (index = 0; index < nb_channels; index++)
   {
      strcpy (channel_id, channel_ids[index]);
      for (equiv_index=-1; equiv_index<nb_equiv; equiv_index++)
      {
         if (equiv_index >= 0)
         {
#ifdef DEBUG
            fprintf (stderr, "Equiv index = %d : '%s' '%s'\n",equiv_index,channel_ids[index], channel_equiv[equiv_index][0]);
#endif
            if (strcmp(channel_ids[index], channel_equiv[equiv_index][0]))
               continue;
            else
               strcpy (channel_id, channel_equiv[equiv_index][1]);
         }
         new_channel = 1;
         for (i=0; i<nb_programs; i++)
         {
            program = programs[(first_program+i)%nb_programs];

            if (program -> channel_id == index)
            {
               if (program->time + program->duration > current_time)
               {
                  if (new_channel)
                  {
                     fprintf (file, "C %s %s\n", channel_id, channels[index]);
                     new_channel = 0;
                  }
                  fprintf (file, "E %d %d %d 90\n", i, (int)(program->time), program->duration);

#ifdef DEBUG
                  fprintf (stderr,"%s %s\n",channel_id, channels[index]);
                  fprintf (stderr,"%s", ctime(&program -> time));

                  /* Duration */
                  fprintf (stderr,"%4d' ", program -> duration / 60);
                  fprintf (stderr,"%10d ", program -> ppv);
                  fprintf (stderr,"%10d ", program -> id);
                  fprintf (stderr,"Summary%s available\n", program -> summary_available ? "" : " NOT");

                  fprintf (stderr,"%s\n",program -> title);
                  fprintf (stderr,"%s ", themes[program -> theme_id]);
#endif
                  summary_found = 0;
                  if (program -> summary_available)
                  {
                     for (j=0; j<nb_summaries; j++)
                        if (program -> id == summaries[j] -> id)
                        {
                           summary_found = 1;
                           summary = summaries[j];
                           strclean (summary -> text);

                           strncpy (long_title, program -> title, sizeof(long_title));
                           strclean (long_title);
                           if ((ptr = strstr (long_title, "...")) != NULL)
                             if (strlen(ptr) == 3)
                             {
                                *ptr = 0;    // Remove ...
                                if ((ptr=strstr (summary -> text, long_title)) != NULL)
                                {
                                   strncpy (long_title, ptr, sizeof(long_title));
                                   if ((ptr=strchr(long_title, '|')) != NULL)
                                      *ptr=0;
                                   else
                                      long_title [sizeof(long_title) - 1] = 0;
                                }
                                else
                                   strncpy (long_title, program -> title, sizeof(long_title));
                             }

                           fprintf (file, "T %s\n", long_title);
                           fprintf (file, "S %s - %d'\n", themes[program -> theme_id], program -> duration / 60);

                           fprintf (file, "D %s", summary -> text);
#ifdef DEBUG
                           fprintf (stderr,"%s\n", summary -> text);
#endif
                           for (n=0; n<summary -> nb_replays; n++)
                           {
                              next_date = localtime (&summary->time[n]);
                              if (n == 0)
                                 fprintf (file,"|Rediffusions:");
                              fprintf (file,"|%02d/%02d/%4d ",next_date->tm_mday,next_date->tm_mon+1,next_date->tm_year+1900);
                              fprintf (file,"%02d:%02d",next_date->tm_hour, next_date->tm_min);
                              if (summary -> channel_id[n] < nb_channels)
	                              fprintf (file," %s",channels[summary -> channel_id[n]]);
                              if (summary -> vm[n])
                                 fprintf (file," - VM");
                              if (summary -> vo[n])
                                 fprintf (file," - VO");
                              if (summary -> subtitles[n])
                                 fprintf (file," - ST");
                              if (summary -> last_replay[n])
                                 fprintf (file," - Dernière diffusion");

#ifdef DEBUG
                              if (summary -> channel_id[n] < nb_channels)
	                              fprintf (stderr,"%s ",channels[summary -> channel_id[n]]);
                              fprintf (stderr,"%2d/%02d/%4d ",next_date->tm_mday,next_date->tm_mon+1,next_date->tm_year+1900);
                              fprintf (stderr,"%02d:%02d",next_date->tm_hour, next_date->tm_min);
                              if (summary -> vm[n])
                                 fprintf (stderr," - VM");
                              if (summary -> vo[n])
                                 fprintf (stderr," - VO");
                              if (summary -> subtitles[n])
                                 fprintf (stderr," - ST");
                                 if (summary -> last_replay[n])
                                    fprintf (stderr," - Last");
                                 fprintf (stderr,"\n");
#endif
                           }
                           fprintf (file, "\n");
                       }
                   }
                   if (!summary_found)
                   {
                       fprintf (file, "T %s\n",program -> title);
                       fprintf (file, "S %s - %d'\n", themes[program -> theme_id], program -> duration / 60);
                   }
                   fprintf (file, "e\n");
               }
#ifdef DEBUG
               fprintf (stderr,"\n");
#endif
            }
         }
         if (!new_channel)
            fprintf (file, "c\n");
      }
   }
   if (filename[0] != 0)
	fclose (file);
   return 0;
}
Example #10
0
void main()
{
	UWORD numCodes;
	UWORD i;
	FILE *fp;
	

	char code[STR_LEN];
	char str[STR_LEN];

	fp=fopen("../ccodes.txt","r");
	
	numCodes=0;
	while(!feof(fp))
	{
		fgets(code,STR_LEN,fp);
		strclean(code);
		if(code[0]=='U')
		{
			char * ptr;
			ptr=strchr(code,' ');
			strcpy(str,ptr);
			*ptr=0;

		}else
		{	
			fgets(str,STR_LEN,fp);
		}
		strclean(str);
		codes[numCodes]=atol(&code[1]); //skip the 'P'
		strcpy(codeStr[numCodes],str);
		if (codes[numCodes]>0)
			numCodes++;
		fgets(code,STR_LEN,fp);
	}
	fclose(fp);


	//now we need to write the codes to a binary file
	fp=fopen("test.bin","wb+");
	for(i=0; i<numCodes; i++)
	{
		UDWORD len,j;
		putDword(fp,codes[i]);
		len=strlen(codeStr[i]);
		if (len%4)
		{
			len=len+(4-(len%4));
		}
		putDword(fp,len);
		for(j=0; j<strlen(codeStr[i]);j++)
		{
			putByte(fp,codeStr[i][j]);
		}
		for(; j<len; j++)
		{
			putByte(fp,0);
		}
	}
	fclose(fp);
	
	for(i=0; i<numCodes; i++)
	{
		printf("P%d\t%s\n",codes[i],codeStr[i]);
	}
	printf("Number of codes %u\n",numCodes);




	return;
}