Free Hero Mesh

Diff
Login
This is a mirror of the main repository for Free Hero Mesh. New tickets and changes will not be accepted at this mirror.

Differences From Artifact [cca5f42c2a]:

To Artifact [6224a071ca]:


990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012

1013
1014
1015
1016
1017
1018
1019
1020

1021
1022
1023
1024
1025
1026
1027
  FILE*fp;
  size_t size=0;
  char*buf=0;
  char*p;
  sqlite3_str*sol=0;
  Value v;
  if(!cmd || !*cmd) return;
  fp=popen(cmd,"r");
  if(!fp) {
    screen_message("Cannot open pipe");
    return;
  }
  discard_solution();
  level_changed=1;
  while(getline(&buf,&size,fp)>0) {
    p=buf;
    p[strcspn(p,"\r\n\f")]=0;
    p+=strspn(p,"\t ");
    switch(*p) {
      case '0' ... '9':
        if(!d) {
          missd:
          screen_message("Missing D line");

          goto done;
        }
        p=import_numbers(p,&x,&y);
        if(!p) goto bad;
        if(x<1 || x>pfwidth || y<1 || y>pfheight) {
          range:
          fprintf(stderr,"Imported level coordinates out of range: %d %d\n",x,y);
          screen_message("Coordinates out of range");

          goto done;
        }
        p=import_value(p,&v);
        if(!p || v.t!=TY_CLASS) goto bad;
        v.u=objalloc(v.u);
        if(v.u==VOIDLINK) goto bad;
        o=objects[v.u];







|















>








>







990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
  FILE*fp;
  size_t size=0;
  char*buf=0;
  char*p;
  sqlite3_str*sol=0;
  Value v;
  if(!cmd || !*cmd) return;
  fp=main_options['i']?stdin:popen(cmd,"r");
  if(!fp) {
    screen_message("Cannot open pipe");
    return;
  }
  discard_solution();
  level_changed=1;
  while(getline(&buf,&size,fp)>0) {
    p=buf;
    p[strcspn(p,"\r\n\f")]=0;
    p+=strspn(p,"\t ");
    switch(*p) {
      case '0' ... '9':
        if(!d) {
          missd:
          screen_message("Missing D line");
          if(main_options['i']) exit(1);
          goto done;
        }
        p=import_numbers(p,&x,&y);
        if(!p) goto bad;
        if(x<1 || x>pfwidth || y<1 || y>pfheight) {
          range:
          fprintf(stderr,"Imported level coordinates out of range: %d %d\n",x,y);
          screen_message("Coordinates out of range");
          if(main_options['i']) exit(1);
          goto done;
        }
        p=import_value(p,&v);
        if(!p || v.t!=TY_CLASS) goto bad;
        v.u=objalloc(v.u);
        if(v.u==VOIDLINK) goto bad;
        o=objects[v.u];
1098
1099
1100
1101
1102
1103
1104



1105
1106
1107
1108

1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
          if(heromesh_key_names[x] && !strcmp(buf+1,heromesh_key_names[x])) {
            sqlite3_str_appendchar(sol,y,x);
            break;
          }
        }
        if(x==256) goto bad;
        break;



      default:
        if(*p && *p!=';') {
          bad:
          fprintf(stderr,"Invalid record in imported data:  %s\n",buf);

          screen_message("Invalid record");
          goto done;
        }
    }
  }
  done:
  free(buf);
  pclose(fp);
  generation_number_inc=0;
  if(sol) {
    solution_length=sqlite3_str_length(sol);
    solution_data=sqlite3_str_finish(sol);
    if(!solution_data) fatal("Allocation failed");
  }
}







>
>
>




>







|







1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
          if(heromesh_key_names[x] && !strcmp(buf+1,heromesh_key_names[x])) {
            sqlite3_str_appendchar(sol,y,x);
            break;
          }
        }
        if(x==256) goto bad;
        break;
      case '=':
        if(main_options['i']) goto done;
        // fall through
      default:
        if(*p && *p!=';') {
          bad:
          fprintf(stderr,"Invalid record in imported data:  %s\n",buf);
          if(main_options['i']) exit(1);
          screen_message("Invalid record");
          goto done;
        }
    }
  }
  done:
  free(buf);
  if(!main_options['i']) pclose(fp);
  generation_number_inc=0;
  if(sol) {
    solution_length=sqlite3_str_length(sol);
    solution_data=sqlite3_str_finish(sol);
    if(!solution_data) fatal("Allocation failed");
  }
}
1706
1707
1708
1709
1710
1711
1712













    "Blank\0" // title
    "\xFF" // objects
  ;
  fwrite(d,1,sizeof(d)-1,fp);
  fflush(fp);
  rewind(fp);
}




















>
>
>
>
>
>
>
>
>
>
>
>
>
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
    "Blank\0" // title
    "\xFF" // objects
  ;
  fwrite(d,1,sizeof(d)-1,fp);
  fflush(fp);
  rewind(fp);
}

void batch_import(void) {
  load_level(level_id);
  if(nobjects) new_level();
  while(!feof(stdin)) {
    if(main_options['v']) fprintf(stderr,"Level %d\n",level_ord);
    import_level("#");
    if(nobjects) {
      save_level();
      if(!feof(stdin)) new_level();
    }
  }
}