thorsson_cups 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/cups.c +26 -36
- metadata +2 -2
data/ext/cups.c
CHANGED
@@ -113,52 +113,42 @@ static VALUE cups_print(VALUE self)
|
|
113
113
|
|
114
114
|
char *fname = RSTRING_PTR(file); // Filename
|
115
115
|
char *target = RSTRING_PTR(printer); // Target printer string
|
116
|
-
|
117
|
-
FILE *fp = fopen(fname,"r");
|
118
|
-
// Check @filename actually exists...
|
119
|
-
if( fp ) {
|
120
|
-
fclose(fp);
|
121
|
-
|
122
|
-
VALUE job_options = rb_iv_get(self, "@job_options");
|
123
|
-
|
124
|
-
// Create an array of the keys from the job_options hash
|
125
|
-
VALUE job_options_keys = rb_ary_new();
|
126
|
-
rb_hash_foreach(job_options, cups_keys_i, job_options_keys);
|
127
116
|
|
128
|
-
|
129
|
-
int num_options = 0;
|
130
|
-
cups_option_t *options = NULL;
|
117
|
+
VALUE job_options = rb_iv_get(self, "@job_options");
|
131
118
|
|
132
|
-
|
133
|
-
|
119
|
+
// Create an array of the keys from the job_options hash
|
120
|
+
VALUE job_options_keys = rb_ary_new();
|
121
|
+
rb_hash_foreach(job_options, cups_keys_i, job_options_keys);
|
122
|
+
|
123
|
+
VALUE iter;
|
124
|
+
int num_options = 0;
|
125
|
+
cups_option_t *options = NULL;
|
134
126
|
|
135
|
-
|
127
|
+
// foreach option in the job options array
|
128
|
+
while (! NIL_P(iter = rb_ary_pop(job_options_keys))) {
|
136
129
|
|
137
|
-
|
138
|
-
if (NIL_P(rb_check_string_type(iter)) || NIL_P(rb_check_string_type(value))) {
|
139
|
-
cupsFreeOptions(num_options, options);
|
140
|
-
rb_raise(rb_eTypeError, "job options is not string => string hash");
|
141
|
-
return Qfalse;
|
142
|
-
}
|
130
|
+
VALUE value = rb_hash_aref(job_options, iter);
|
143
131
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
132
|
+
// assert the key and value are strings
|
133
|
+
if (NIL_P(rb_check_string_type(iter)) || NIL_P(rb_check_string_type(value))) {
|
134
|
+
cupsFreeOptions(num_options, options);
|
135
|
+
rb_raise(rb_eTypeError, "job options is not string => string hash");
|
136
|
+
return Qfalse;
|
148
137
|
}
|
149
138
|
|
150
|
-
|
139
|
+
// convert to char pointers and add to cups optoins
|
140
|
+
char * iter_str = rb_string_value_ptr(&iter);
|
141
|
+
char * value_str = rb_string_value_ptr(&value);
|
142
|
+
cupsAddOption(iter_str, value_str, num_options++, &options);
|
143
|
+
}
|
151
144
|
|
152
|
-
|
145
|
+
job_id = cupsPrintFile(target, fname, "rCUPS", num_options, options); // Do it. "rCups" should be the filename/path
|
153
146
|
|
154
|
-
|
147
|
+
cupsFreeOptions(num_options, options);
|
155
148
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
rb_raise(rb_eRuntimeError, "Couldn't find file");
|
160
|
-
return Qfalse;
|
161
|
-
}
|
149
|
+
rb_iv_set(self, "@job_id", INT2NUM(job_id));
|
150
|
+
|
151
|
+
return Qtrue;
|
162
152
|
}
|
163
153
|
|
164
154
|
/*
|