Beispiel #1
0
/**
 * 前後の空白を取り除く
 * 
 * @param string	処理対象の文字列
 * @return	前後の空白を取り除いた文字列へのポインタ
 */
char *
strstrip(char *string)
{
    assert(NULL != string);

    return strlstrip(strrstrip(string));
}
Beispiel #2
0
int
config_read(FILE *fp, char **keyp, char **valuep, int *lineno)
{
    char *token, *line = NULL;
    char *key, *value;
    size_t len = 0;
    ssize_t nread;

    *keyp = NULL;
    *valuep = NULL;

    do {
        errno = 0;
        if ((nread = getline(&line, &len, fp)) < 0)
            goto err;

        (*lineno)++;

        strrstrip(line, nread, whitespace);
        token = line + strspn(line, whitespace);
        key = strsep(&token, whitespace);

        if (token != NULL)
            value = token + strspn(token, whitespace);
        else
            value = "";
    } while (key[0] == '#' || key[0] == '\0');

    if ((*keyp = strdup(key)) == NULL)
        goto err;
    if ((*valuep = strdup(value)) == NULL)
        goto err;

    free(line);
    return 1;

err:
    free(line);
    free(*keyp);
    free(*valuep);
    return errno == 0 ? 0 : -1;
}
Beispiel #3
0
Datei: ls.c Projekt: z88dk/z88dk
int main(int argc, char **argv)
{
   static unsigned char *name;
   static unsigned char cwd[ESX_PATHNAME_MAX + 1];
   
   static struct esx_stat es;
   static struct esx_dirent ed;
   static struct esx_dirent_slice *slice;

   // initialization
   
   old_cpu_speed = ZXN_READ_REG(REG_TURBO_MODE);
   ZXN_NEXTREG(REG_TURBO_MODE, RTM_14MHZ);
   
   atexit(cleanup);
   
   // if a filename is not listed use the current working directory
   
   name = strrstrip(strstrip(argv[1]));
   
   if ((argc == 1) || (strcmp(name, ".") == 0))
   {
      if (esx_f_getcwd(cwd) == 0xff) exit(errno);
      name = cwd;
   }
   
   // try to open as a directory
   
   if ((fin = esx_f_opendir(name)) != 0xff)
   {
      // directory

      while (esx_f_readdir(fin, &ed) == 1)
      {
         slice = esx_slice_dirent(&ed);
         
         ls_name = ed.name;
         ls_size = &slice->size;
         
         tm_from_dostm(&ls_tm, &slice->time);
         
         (ed.attr & ESX_DIR_A_DIR) ? ls_dir() : ls_file();
      }
      
      esx_f_close(fin);
      fin = 0xff;
   }
   else
   {
      // file
      
      if (esx_f_stat(name, &es)) exit(errno);
      
      ls_name = name;
      ls_size = &es.size;
      
      tm_from_dostm(&ls_tm, &es.time);
      
      (es.attr & ESX_DIR_A_DIR) ? ls_dir() : ls_file();
   }
   
   return 0;
}