I did some more work on this tonight and it now can rename files within a group as well as single files. My next plan is to attack creating group files and modifying attributes such as locked and archived. The attribute code should be pretty easy to do once I figure out a good way for the user to specify attributes. I may just steal from ben moody's GPL'd ti tools here because from what I saw he has some nice code to do this and that way the programs will accept the same formats.
Edit: Here's the code so far.
Code: /*
* tifile
*
* Copyright (c) 2010 Jon Sturm
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <string.h>
#include <tilp2/tifiles.h>
/* Flag set by ‘--verbose’. */
static int verbose_flag;
enum modes {MODE_NONE, MODE_HELP, MODE_EX, MODE_LS, MODE_CREATE, MODE_ADD, MODE_DEL, MODE_MOD};
int
main(int argc, char *argv[])
{
char c;
int curmode=MODE_NONE;
static struct option long_options[] = {
{"help", 0, 0, 'h'},
{"version", 0, 0, 'V'},
{"entry", required_argument, 0, 'e'},
{"rename", required_argument, 0, 'r'},
{"list", required_argument, 0, 'l'},
{"extract", required_argument, 0, 'x'},
{"verbose", 0, &verbose_flag, 'v'},
{0, 0, 0, 0}
};
char *ofile=NULL, *ifile=NULL;
int option_index = 0;
int entry=0;
char *newname=NULL;
FileContent *regular;
CalcModel model;
while ((c = getopt_long(argc, argv, ":hVvl:x:r:e:", long_options, &option_index)) != -1) {
switch (c) {
case 'V':
printf("Insert Verison Text here\n");
break;
default:
case 'h':
curmode=MODE_NONE;
break;
case 'x':
if (curmode==MODE_NONE && optarg){
curmode = MODE_EX;
ifile=optarg;
}
else {
curmode = MODE_HELP;
}
break;
case 'e':
if (optarg)
entry= (int)strtol(optarg, NULL, 10);
break;
case 'r':
if ((curmode==MODE_NONE || curmode==MODE_MOD) && optarg){
curmode = MODE_MOD;
newname=optarg;
}
else {
curmode = MODE_HELP;
}
break;
case 'l':
if (curmode==MODE_NONE && optarg){
curmode = MODE_LS;
ifile=optarg;
}
else {
curmode = MODE_HELP;
};
break;
case ':': /* -f or -o without operand */
fprintf(stderr,
"Option -%c requires an operand\n", optopt);
curmode=MODE_HELP;
break;
case '?':
fprintf(stderr,
"Unrecognised option: -%c\n", optopt);
curmode=MODE_HELP;
case 'v':
verbose_flag++;
break;
}
}
// if (optind < argc)
// {
// printf ("non-option ARGV-elements: ");
// while (optind < argc)
// printf ("%s ", argv[optind++]);
// putchar ('\n');
// }
if (curmode==MODE_MOD)
ifile=argv[optind++];
if (curmode==MODE_HELP || curmode==MODE_NONE) printf("insert help text here\n");
tifiles_library_init();
if (curmode==MODE_EX){
int err = 0;
//printf("%x [%s]\n",(void*)ifile,ifile);
if (tifiles_file_is_group(ifile))
tifiles_ungroup_file(ifile, NULL);
else if(tifiles_file_is_tigroup(ifile))
tifiles_untigroup_file(ifile, NULL);
else
fprintf(stderr, "invalid filetype");
}
if (curmode==MODE_MOD){
//printf("%x [%s]\n",(void*)ifile,ifile);
if (tifiles_file_is_regular(ifile)){
CalcModel model = tifiles_file_get_model(ifile);
regular = tifiles_content_create_regular(model);
tifiles_file_read_regular(ifile, regular);
if (entry > regular->num_entries || entry <0) {
fprintf(stderr, "invalid entry specified");
return 0;
}
if(newname!=NULL){
char *str;
str = ticonv_varname_tokenize(model, newname, regular->entries[entry]->type);
if(strlen(str) > 8)
str[8] = '\0';
strcpy(regular->entries[entry]->name, str);
}
tifiles_file_write_regular(ifile, regular, NULL);
}else
fprintf(stderr, "invalid filetype");
}
if (curmode==MODE_LS){
int err = 0;
//printf("%x [%s]\n",(void*)ifile,ifile);
if (tifiles_file_is_regular(ifile))
tifiles_file_display(ifile);
else if(tifiles_file_is_tigroup(ifile))
tifiles_file_display_tigroup(ifile);
else
fprintf(stderr, "invalid filetype");
}
tifiles_library_exit();
return 0;
}