예제 #1
0
파일: my_apr.c 프로젝트: fave-r/Zappy
int	my_apr(char **com, t_zap *data, t_user *usr)
{
  int		ig;
  int		ask_nb;
  t_ask		*ask;

  if (sstrlen(com) > 3 || sstrlen(com) == 1)
    return (my_sbp(usr));
  if (sstrlen(com) == 1)
    return (aeg_response(data, usr, APR));
  if ((ig = my_strtol(com[1])) == -1 ||
      (ask_nb = my_strtol(com[2])) == -1)
    return (my_sbp(usr));
  if ((ask = get_asking(usr, ig, ask_nb)) == NULL)
    return (my_sbp(usr));
  ask->res |= APR;
  return (0);
}
예제 #2
0
파일: getline.c 프로젝트: seblu/42sh
/*
** Append a string to the buffer string
*/
static void     buf_str(char **str, char *append, unsigned n)
{
  unsigned      ln;
  unsigned      i;
  unsigned      j;

  ln = sstrlen(*str);
  secrealloc(*str, *str, (ln + n + 1) * sizeof (char));
  for (i = ln, j = 0; i < ln + n; i++, j++)
    (*str)[i] = append[j];
  (*str)[ln + n] = 0;
}
예제 #3
0
int
cl2knj(u_char *yomi, int len, u_char *kouho)
{
	u_char	*ptr1;
	u_char	*ptr2;
	int	i;

	khcount = nkhcount = 0;

	initkbuf(kouho);

	if (len > MAXCLINPUTLEN * 2) len = MAXCLINPUTLEN * 2;

	ptr1 = yomi; ptr2 = hyomi;
	for (i = 0 ; i < len ; i++) {
		if (isknj1(*ptr1)) {
			if (++i >= len) break;
		}
		ptr1 += sj2cd_chr(ptr1, ptr2++);
	}
	*ptr2 = 0;

	strlcpy(orgyomi, yomi, (int)(ptr1 - yomi) + 1);

	if (!hyomi[0]) return 0;

	freework();

	inputyomi = orgyomi;
	cnvstart = ystart = hyomi;
	cnvlen = sstrlen(hyomi);

	mkjiritu(0);

	mkbunsetu();

	if (!maxclptr) wakachi();

	jrt1st = maxjptr;
	clt1st = maxclptr;

	mkkouho();

	getrank();

	selectid = 1;

	cvtclknj();

	return hzstrlen(inputyomi, (int)clt1st -> cllen);
}
예제 #4
0
int		my_inventaire(char **com, t_zap *data, t_user *usr)
{
  t_content	cnt;
  char		tmp[150];
  t_tv		now;

  (void)data;
  if (sstrlen(com) != 1)
    return (-1);
  gettimeofday(&now, NULL);
  cnt = GET_INV(usr);
  bzero(tmp, 150);
  sprintf(tmp, "{nourriture %d, linemate %d, deraumere %d,\
 sibur %d, mendiane %d, phiras %d, thystame %d}\n",
예제 #5
0
/*   compare strings   */
static int scompare(char *buff1, const char *buff2)
{
	int i;

	if (sstrlen(buff1) == sstrlen(buff2)) {
		if (sstrcmp(buff1,buff2) == 0) {
			if (fgets(buff1,4095,fp)==NULL) return -1;
			return 0;
		}
		return -1;
	}
	for (i=0;i<sstrlen(buff1)-sstrlen(buff2);i++) {
		if (buff1[i]==' ' || buff1[i]=='\t') {
			continue;
		}
		else if ((sstrncmp(&buff1[i],buff2,sstrlen(buff2))==0)
			&&((buff1[i+strlen(buff2)]==' ')||(buff1[i+strlen(buff2)]=='\t')||(buff1[i+strlen(buff2)]=='\n'))) {
			return i+strlen(buff2);
		}
		else return -1;
	}
	return -1;
}
예제 #6
0
파일: my_pin.c 프로젝트: fave-r/Zappy
int	my_pin(char **com, t_zap *data, t_user *usr)
{
  int		nb;
  t_user	*player;

  (void)data;
  if (sstrlen(com) != 2)
    return (my_sbp(usr));
  nb = my_strtol(com[1]);
  if (nb == -1)
    return (my_sbp(usr));
  player = usr;
  while (player != NULL && player->prev != NULL)
    player = player->prev;
  while (player != NULL)
    {
      if (player->type == AI && player->nb == nb)
	return (my_send_pin(usr, player));
      player = player->next;
    }
  return (0);
}
예제 #7
0
파일: conf.c 프로젝트: ColumPaget/gngeo-cjp
//generate config-file default path for various systems
char *cf_default_path(char *conf_file, const char *filename, const char *extn)
{
int len;

		len=sstrlen(filename)+sstrlen(extn);

#ifdef EMBEDDED_FS
		len+= sstrlen(ROOTPATH) + sstrlen("conf/") + 1;
		conf_file = (char *) realloc(conf_file, len * sizeof (char));
		sprintf(conf_file, "%s%s%s%s",ROOTPATH,"conf/",filename,extn);
#elif __AMIGA__
		len+=sstrlen("/PROGDIR/data/") + 1;
		conf_file = (char *) realloc(conf_file, len * sizeof (char));
		sprintf(conf_file, "%s%s%s","/PROGDIR/data/",filename,extn);
#else
		len += sstrlen(getenv("HOME")) + sstrlen("/.gngeo/") + 1;
		conf_file = (char *) realloc(conf_file, len * sizeof (char));
		sprintf(conf_file, "%s/.gngeo/%s%s", getenv("HOME"),filename,extn);
#endif

return(conf_file);
}
예제 #8
0
파일: conf.c 프로젝트: ColumPaget/gngeo-cjp
bool cf_save_file(char *filename, int flags) {
	char *conf_file = NULL;
	char *conf_file_dst;
	FILE *f;
	FILE *f_dst;
	int i = 0, j, a;
	char buf[512];
	char *name=NULL, *ptr;
	CONF_ITEM *cf;

	if (! sstrlen(filename)) conf_file=cf_default_path(conf_file, "gngeorc", "");
	else conf_file=rstrcpy(conf_file, filename, 1024);

	conf_file_dst = alloca(strlen(conf_file) + 4);
	sprintf(conf_file_dst, "%s.t", conf_file);

	if ((f_dst = fopen(conf_file_dst, "w")) == 0) {
		//printf("Unable to open %s\n",conf_file);
		if (conf_file) free(conf_file);
		return false;
	}

	if ((f = fopen(conf_file, "rb"))) {

		//printf("Loading current .cf\n");

		while (!feof(f)) {
			i = 0;
			my_fgets(buf, 510, f);
			if (discard_line(buf)) {
				fprintf(f_dst, "%s\n", buf);
				continue;
			}

			//this is an odd approach, seeks to replace existing config
			//items in the order they exist in config file?
			ptr=get_token(buf, " ", &name);

			cf = cf_get_item_by_name(name);
			if (cf) {
				if (cf->modified) {
					cf->modified = 0;
					switch (cf->type) {
						case CFT_INT:
							fprintf(f_dst, "%s %d\n", cf->name, CF_VAL(cf));
							break;
						case CFT_BOOLEAN:
							if (CF_BOOL(cf))
								fprintf(f_dst, "%s true\n", cf->name);
							else
								fprintf(f_dst, "%s false\n", cf->name);
							break;
						case CFT_STRING:
							fprintf(f_dst, "%s %s\n", cf->name, CF_STR(cf));
							break;
						case CFT_ARRAY:
							fprintf(f_dst, "%s ", cf->name);
							for (a = 0; a < CF_ARRAY_SIZE(cf) - 1; a++)
								fprintf(f_dst, "%d,", CF_ARRAY(cf)[a]);
							fprintf(f_dst, "%d\n", CF_ARRAY(cf)[a]);
							break;
						case CFT_ACTION:
						case CFT_ACTION_ARG:
							break;
						case CFT_STR_ARRAY:
							printf("TODO: Save CFT_STR_ARRAY\n");
							break;
					}
				} else
					fprintf(f_dst, "%s\n", buf);
			}
		}
		fclose(f);

	}
	/* Now save options that were not in the previous file */
	for (i = 0; i < 128; i++) {
		for (j = 0; j < cf_hash[i].nb_item; j++) {
			cf = cf_hash[i].conf[j];
			//printf("Option %s %d\n",cf->name,cf->modified);
			if (cf->modified!=0) {
				cf->modified=0;
				switch (cf->type) {
					case CFT_INT:
						fprintf(f_dst, "%s %d\n", cf->name, CF_VAL(cf));
						break;
					case CFT_BOOLEAN:
						if (CF_BOOL(cf))
							fprintf(f_dst, "%s true\n", cf->name);
						else
							fprintf(f_dst, "%s false\n", cf->name);
						break;
					case CFT_STRING:
						fprintf(f_dst, "%s %s\n", cf->name, CF_STR(cf));
						break;
					case CFT_ARRAY:
						fprintf(f_dst, "%s ", cf->name);
						for (a = 0; a < CF_ARRAY_SIZE(cf) - 1; a++)
							fprintf(f_dst, "%d,", CF_ARRAY(cf)[a]);
						fprintf(f_dst, "%d\n", CF_ARRAY(cf)[a]);
						break;
					case CFT_ACTION:
					case CFT_ACTION_ARG:
						/* action are not available in the conf file */
						break;
					case CFT_STR_ARRAY:
						printf("TODO: Save CFT_STR_ARRAY\n");
						break;
				}
			}
		}
	}
	fclose(f_dst);

	remove(conf_file);
	rename(conf_file_dst, conf_file);

	if (name) free(name);
	if (conf_file) free(conf_file);

	return true;
}
예제 #9
0
MRESULT EXPENTRY MaskDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) {
   static PMASKSEL pmask;
   static BOOL flag = FALSE;   // TRUE se Š stato aggiunto o tolto un elemento
   static int idx;             // posizione item selezionato o di inserzione

   switch (msg) {
      case WM_INITDLG: {
         CHAR buf[FACESIZE];
         PSZ pszCur;
         int len;
         pmask = (PMASKSEL)PVOIDFROMMP(mp2);      // recupera indirizzo dati
         // imposta il font della barra del titolo:
         PrfQueryProfileString(HINI_USERPROFILE, "PM_SystemFonts",
                               "WindowTitles", "9.WarpSans", buf, FACESIZE);
         WinSetPresParam(WinWindowFromID(hwnd, FID_TITLEBAR), PP_FONTNAMESIZE,
                         sstrlen(buf) + 1, (PVOID)(buf));
         WinSetWindowPos(hwnd, HWND_BOTTOM, pmask->pos.x, pmask->pos.y, 0, 0,
                         SWP_MOVE | SWP_SHOW);    // visualizza la finestra
         pszCur = pmask->pszExt;
         DlgEFSetTxtLimit(hwnd, COMBO_MASK, 63);
         // riempie la listbox
         while (len = sstrlen(pszCur)) {
            DlgLboxInsertItem(hwnd, COMBO_MASK, LIT_SORTASCENDING, pszCur);
            pszCur += len + 1;
         } /* endwhile */
         } // end case WM_INITDLG:
         break;
      case WM_CONTROL:
         switch (SHORT2FROMMP(mp1)) {
            case CBN_EFCHANGE: {          // cambiamento testo
               BOOL enable;
               // pulsante OK abilitato se c'e' testo nell' entrifield
               enable = WinQueryDlgItemTextLength(hwnd, COMBO_MASK);
               WinEnableControl(hwnd, MASK_OK, enable);
               // pulsante ADD abilitato se c'Š testo non gi… presente
               WinQueryDlgItemText(hwnd, COMBO_MASK, 64, pmask->achSel);
               idx = isInListBox(hwnd, pmask->achSel, COMBO_MASK); 
               WinEnableControl(hwnd, MASK_STORE, enable && (idx < 0));
               // pulsante REMOVE abilitato se testo EF == item lista
               WinEnableControl(hwnd, MASK_DEL, idx >= 0);
               } // end case CBN_EFCHANGE:
               break;
            case CBN_LBSELECT:            // selezione item
               idx = isInListBox(hwnd, pmask->achSel, COMBO_MASK);
               WinEnableControl(hwnd, MASK_DEL, idx >= 0);
               break;
            default:
              break;
         } /* endswitch */
         break;
      case WM_COMMAND:
         switch (LOUSHORT(mp1)) {
            case MASK_OK:
               WinQueryDlgItemText(hwnd, COMBO_MASK, 64, pmask->achSel);
               if (flag)    // eventualmente aggiorna lista filespec
                  ProcMaskDlgExit(hwnd, pmask);
               SaveMaskDlgPos(hwnd, pmask);
               WinDismissDlg(hwnd, TRUE);
               break;
            case MASK_STORE:
               flag = TRUE;
               DlgLboxInsertItem(hwnd, COMBO_MASK, LIT_SORTASCENDING,
                                 pmask->achSel);
               DlgLboxSelectItem(hwnd, COMBO_MASK, -idx - 1);
               WinEnableControl(hwnd, MASK_STORE, FALSE);
               break;
            case MASK_DEL:
               flag = TRUE;
               idx = DlgLboxQuerySelectedItem(hwnd, COMBO_MASK);
               DlgLboxDeleteItem(hwnd, COMBO_MASK, idx);
               WinSetDlgItemText(hwnd, COMBO_MASK, "");
               break;
            default: 
               if (flag)    // eventualmente aggiorna lista filespec
                  ProcMaskDlgExit(hwnd, pmask);
               SaveMaskDlgPos(hwnd, pmask);
               WinDismissDlg(hwnd, FALSE);
               break;
         } /* endswitch */
         break;
      case WM_CLOSE:
         if (flag)    // eventualmente aggiorna lista filespec
            ProcMaskDlgExit(hwnd, pmask);
         SaveMaskDlgPos(hwnd, pmask);
         WinDismissDlg(hwnd, FALSE);
         break;
      default: 
         return WinDefDlgProc(hwnd, msg, mp1, mp2);
   } // end switch
   return (MRESULT) FALSE;
}
예제 #10
0
파일: my_msz.c 프로젝트: fave-r/Zappy
int	my_msz(char **com, t_zap *data, t_user *usr)
{
  if (sstrlen(com) != 1)
    return (my_sbp(usr));
  return (my_send_msz(data, usr));
}