]> err.no Git - sope/blob - sope-gdl1/GDLContentStore/gcs_gensql.m
added OGoContentStore library to sope-gdl1
[sope] / sope-gdl1 / GDLContentStore / gcs_gensql.m
1 /*
2   Copyright (C) 2005 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
6   OGo is free software; you can redistribute it and/or modify it under
7   the terms of the GNU Lesser General Public License as published by the
8   Free Software Foundation; either version 2, or (at your option) any
9   later version.
10
11   OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12   WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14   License for more details.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with OGo; see the file COPYING.  If not, write to the
18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19   02111-1307, USA.
20 */
21
22 #import <Foundation/NSObject.h>
23
24 @class NSUserDefaults, NSArray;
25 @class GCSFolderManager;
26
27 @interface Tool : NSObject
28 {
29   NSUserDefaults *ud;
30 }
31
32 + (int)runWithArgs:(NSArray *)_args;
33 - (int)run;
34
35 @end
36
37 #include <GDLContentStore/GCSFolderType.h>
38 #include "common.h"
39
40 @implementation Tool
41
42 - (id)init {
43   if ((self = [super init])) {
44     self->ud = [[NSUserDefaults standardUserDefaults] retain];
45   }
46   return self;
47 }
48 - (void)dealloc {
49   [self->ud release];
50   [super dealloc];
51 }
52
53 /* operation */
54
55 - (int)runOnTable:(NSString *)_tableName typeName:(NSString *)_typeName {
56   GCSFolderType *folderType;
57   
58   if ((folderType = [GCSFolderType folderTypeWithName:_typeName]) != nil) {
59     NSString *s;
60     
61     s = [folderType sqlQuickCreateWithTableName:_tableName];
62     
63     fwrite([s cString], 1, [s cStringLength], stdout);
64     printf("\n");
65   }
66   else {
67     fprintf(stderr, "ERROR: did not find GCS type: '%s'\n", 
68             [_typeName cString]);
69   }
70   
71   return 0;
72 }
73
74 - (int)run {
75   NSEnumerator *e;
76   NSString *tableName, *typeName;
77   
78   e = [[[NSProcessInfo processInfo] argumentsWithoutDefaults] 
79                        objectEnumerator];
80   [e nextObject]; // skip tool name
81   
82   while ((tableName = [e nextObject]) != nil) {
83     typeName = [e nextObject];
84     if (typeName == nil) {
85       [self logWithFormat:@"got tablename '%@' but no type?!", tableName];
86       break;
87     }
88     
89     [self runOnTable:tableName typeName:typeName];
90   }
91   
92   return 0;
93 }
94 + (int)runWithArgs:(NSArray *)_args {
95   return [(Tool *)[[[self alloc] init] autorelease] run];
96 }
97
98 @end /* Tool */
99
100 int main(int argc, char **argv, char **env) {
101   NSAutoreleasePool *pool;
102   int rc;
103
104   pool = [[NSAutoreleasePool alloc] init];
105 #if LIB_FOUNDATION_LIBRARY  
106   [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
107 #endif
108
109   rc = [Tool runWithArgs:
110                [[NSProcessInfo processInfo] argumentsWithoutDefaults]];
111   
112   [pool release];
113   return rc;
114 }